Skip to content

BernardoSilva/jwt-api-client-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 = 'api.your-domain.pt';


$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']);
$client->setCredentials($credentials);

// e.g. Request types
$client->get();
$client->delete();
$client->patch();
$client->post();
$client->put();

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

License

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

About

PHP API Client to facilitate consuming JWT protected API's

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages