Laravel passport refresh token Laravel passport refresh token laravel laravel

Laravel passport refresh token


If your application issues short-lived access tokens, users will need to refresh their access tokens via the refresh token that was provided to them when the access token was issued. In this example, we'll use the Guzzle HTTP library to refresh the token:

$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);

This /oauth/token route will return a JSON response containing access_token, refresh_token, and expires_in attributes. The expires_in attribute contains the number of seconds until the access token expires.


I've done something like.

Created an endpoint for grant refresh token.and in my controller,

public function userRefreshToken(Request $request){$client = DB::table('oauth_clients')    ->where('password_client', true)    ->first();$data = [    'grant_type' => 'refresh_token',    'refresh_token' => $request->refresh_token,    'client_id' => $client->id,    'client_secret' => $client->secret,    'scope' => ''];$request = Request::create('/oauth/token', 'POST', $data);$content = json_decode(app()->handle($request)->getContent());return response()->json([    'error' => false,    'data' => [        'meta' => [            'token' => $content->access_token,            'refresh_token' => $content->refresh_token,            'type' => 'Bearer'        ]    ]], Response::HTTP_OK);}