0
votes

I perform the steps described in this Questions:

Laravel's 5.3 passport and api routes

Everything works fine from the routes of the api, I can register new users, read their data etc etc.

Then add this command on AuthServiceProvider

Passport::tokensExpireIn(Carbon::now()->addMinute(2)); Passport::refreshTokensExpireIn(Carbon::now()->addDays(1));

i login in postman in url {{url}}/oauth/token

Body: application/x-www-form-urlencoded
{
grant_type : 'password'
client_id : {{email with which the user is registered}}
client_secret : {{generate the client secret from the mobile app}}
username : {{email with which the user is registered}}
password : {{password entered by the user}}
scope : ''
}

the response its successful

{
"token_type": "Bearer"
"expires_in": 120
"access_token": {{the access_token}}
"refresh_token": {{the refresh_token}}
}

I try to refresh token life time to one day send to {{url}}/oauth/token

ref => https://laravel.com/docs/5.3/passport#refreshing-tokens

in postman i send

Headers:

Authorization : Bearer {{the access_token}}

Body: application/x-www-form-urlencoded
{
client_secret : {{generate the client secret from the mobile app}}
grant_type : refresh_token
refresh_token : {{the refresh_token}}
client_id : {{email with which the user is registered}}
scope : ''
}

The expected response:

{
"access_token": {{new access_token}}
"token_type": 'Bearer'
"expires_in": 86400
"refresh_token": {{new access_token}}
}

But it does not work as expected, the response its

{
"access_token": {{new access_token}}
"token_type": 'Bearer'
"expires_in": 120
"refresh_token": {{new access_token}}
}

3

3 Answers

2
votes

Because you're generating access_token using refresh_token. So it shows the expiration time of access_token i.e 2 minutes which is set by this line:

Passport::tokensExpireIn(Carbon::now()->addMinute(2));
1
votes

Also, you should be sending the client id (id field integer) from your oauth_clients table... not your clients email address

1
votes
 public function boot()
    {
        $this->registerPolicies();
        Passport::routes();
        Passport::tokensExpireIn(now()->addDays(1));
        Passport::refreshTokensExpireIn(now()->addDays(1));
        Passport::personalAccessTokensExpireIn(now()->addMonths(6));

    }