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
Asked
Active
Viewed 300 times
1 Answers
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
-
1Note that the new version of firebase/php-jw will throw an error when the token expires. – jcubic Jun 16 '23 at 08:57