javis / password-grant-client
A PHP library to easily OAuth2 to your APIs using the Password Grant
v1.1.3
2020-11-04 19:07 UTC
Requires
- php: >=5.5.9
- league/oauth2-client: ^1.4
Requires (Dev)
- mockery/mockery: ^0.9
- phpunit/phpunit: ^4.8
README
A PHP library to easily authorize OAuth 2.0 APIs using the Password Grant. This is a wrapper of the amazing The League of Extraordinary Packages OAuth2 Client, but it automates the process of storing the token in session and refreshing it when necessary
Requirements
- PHP >= 5.5
Installation
composer require javis/password-grant-client
Usage
Configuring the client
Create a Client Provider with the configuration to the endpoints and then provide the instance to the OAuth2 Client.
$provider = new \League\OAuth2\Client\Provider\GenericProvider([ 'clientId' => 'demoapp', // The client ID assigned to you by the provider 'clientSecret' => 'demopass', // The client password assigned to you by the provider 'urlAccessToken' => 'http://brentertainment.com/oauth2/lockdin/token' ]); $client = new \Javis\OAuth2\PasswordGrantClient($provider);
Requesting an access token
When requesting the token, the Client will automatically check for if it was already stored in Session or if it needs to refresh it, and perform all required operations before returning it.
$return = $client->getAccessToken('username', 'password'); echo $token->getToken();
Forgetting stored token
$client->forgetToken();