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
- PHP >= 5.5
composer require javis/password-grant-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);
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();
$client->forgetToken();