bernardosilva / jwt-api-client-php
API client prepared to consume API using JWT for PHP
Installs: 15 243
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=5.5
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- bernardosilva/git-hooks-php: ^2.0
- phpunit/phpunit: >=4.8
This package is auto-updated.
Last update: 2024-10-29 05:22:30 UTC
README
Jason Web Token API client is a library to facilitate consuming API's that require JWT token as authentication.
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.