André Figueira

Systems engineer - I write apps, I make websites, opinions are my own...

PHP League oAuth 2.0 password grant usage


Firstly, make sure you have an instance of your provider, in this example, I'll just be using the GenericProvider.

$client = new oAuth2Client([
    'clientId' => 'client_id',
    'clientSecret' => 'client_secret',
    'redirectUri' => null,
    'urlAuthorize' => null,
    'urlAccessToken' => '/your/oauth/token/endpoint',
    'urlResourceOwnerDetails' => null,

Once you've got that, you obviously want to get your access token, so it's quite easy, just pass in password, as the grant type and the relevant options.

$accessToken = $client->getAccessToken('password', [
    'username' => 'your_username',
    'password' => 'your_password',