API client prepared to consume API using JWT for PHP

0.0.3 2018-01-15 15:05 UTC


JWT API Client for PHP

Jason Web Token API client is a library to facilitate consuming API's that require JWT token as authentication.

Latest Stable Version Total Downloads Build Status License

How to Install

$ composer require bernardosilva/jwt-api-client-php

How to use

use BernardoSilva\JWTAPIClient\APIClient;
use BernardoSilva\JWTAPIClient\AccessTokenCredentials;

$username = 'your-username';
$password = 'your-password';
$baseURI = '';

$client = new APIClient($baseURI);
$options = [
    'verify' => false, // might need this if API uses self signed certificate
    'form_params' => [
        'key' => $username,
        'password' => $password

// authenticate on API to get token
$response = $client->post('/api/v1/auth/login', $options);
$loginResponseDecoded = json_decode($response->getBody()->getContents(), true);

$credentials = new AccessTokenCredentials($loginResponseDecoded['access_token']);

// e.g. Request types

Example of how to get access token without requesting the API:

// When using internally with other services can generate accessToken directly
$accessToken = $JWTManager->create($user);
$credentials = new AccessTokenCredentials($accessToken);

How to contribute

  • Fork project
  • Clone it to your machine
  • Install dependencies using composer install
  • Open a Pull Request

How to test

$ ./vendor/bin/phpunit

Created by


The source code is licensed under GPL v3. License is available here.