Laravel Passport Password Grant Refresh Token

后端 未结 2 1391
慢半拍i
慢半拍i 2021-01-05 08:18

Trying to wrap my head around using Laravel\'s Passport with mobile clients. The Password Grant type of authentication seems to be the way to go, and i have it working with

2条回答
  •  执笔经年
    2021-01-05 08:58

    The oauth/token/refresh route is not for refreshing access tokens. It is used to refresh transient tokens, which are used when you consume your own API from your javascript.

    To use your refresh_token to refresh your access token, you need to call the oauth/token route with the grant_type of refresh_token.

    This is the example provided by the documentation:

    $http = new GuzzleHttp\Client;
    
    $response = $http->post('http://your-app.com/oauth/token', [
        'form_params' => [
            'grant_type' => 'refresh_token',
            'refresh_token' => 'the-refresh-token',
            'client_id' => 'client-id',
            'client_secret' => 'client-secret',
            'scope' => '',
        ],
    ]);
    
    return json_decode((string) $response->getBody(), true);
    

    One note about scopes, when you refresh the token, you can only obtain identical or narrower scopes than the original access token. If you attempt to get a scope that was not provided by the original access token, you will get an error.

提交回复
热议问题