I need to generate an access token while a method on a controller will be get called by a specific route. My question is how to generate a new access token for logged in user and replace it with the old one (in oauth_access_tokens table e.a. updating user status or token).
I need to delete the old access token and replace it by a new one . In my case, The passport has a life-time and every time that user does something or accomplish or fulfill an action (e.g. call a route, etc...), I need to generate a new access token and replace it to the existing one.
In documentation, it is pretty clearly mentioned, you need to use your access token, to generate a refresh token and you can replace your existing access token with that.
$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);
now there are a number of options you could employ:
Look at oauth_access_tokens
and oauth_refresh_tokens
, tables, that will help you to understand what you need to update here manually.