2

I am using the firebase/php-jwt library to authenticate users, I am successfully able to send the access-token, but how can I send a refresh token and create a way to revalidate the refresh token after its expiry

HOSENUR
  • 305
  • 3
  • 12

1 Answers1

0

you could try something like

public function refreshToken($request)
{
    $refreshTokenSecret = 'your-refresh-token-secret-key';
    $previousToken = $request->get('previous_token'); // get token from request

    // Make sure previous token is ok
    $refreshTokenData = JWT::decode($previousToken, $refreshTokenSecret, ['HS256']);

    if ($refreshTokenData->exp < time()) {
        throw new Exception('Refresh token has expired'); // throw exception if token is expired
    }

    $previousTokenData = $refreshTokenData->data;

    $newToken = JWT::encode($previousTokenData, $refreshTokenSecret);

    // Send the new access token back to the client
}
Xander-Nova
  • 129
  • 2