I'm using Passport on Laravel 5.5, receiving error when trying to refresh access token - only on production server - local dev environment works fine!
This is the error returned:
{
"error": "invalid_request",
"message": "The refresh token is invalid.",
"hint": "Token is not linked to client"
}
I've verified that the tokens and clients exist on the database, are not expired, have not been revoked, are stored correctly etc.
Because the system is a multi-tenant system (with each tenant having it's own database) I did not create passport clients using the command
php artisan passport:client
instead I copied the passport oauth_clients
table and contents for each tenant - so that each tenant uses the same client credentials for eg logging in from frontend, logging in from app (but with different endpoints).
I'm at a loss as to why it's working fine on my local machine but not production.
Does anyone know what exactly php artisan passport:client
does besides creating a row in oauth_clients
table?
I'm thinking that perhaps something more than just copying the oauth_clients
table contents is needed..
Any advice appreciated! Thanks
Well after digging around in vendor code I fixed the problem by modifying
vendor/league/oauth2-server/src/Grant/RefreshTokenGrant.php
function validateOldRefreshToken
changed
if ($refreshTokenData['client_id'] !== $clientId) {
$this->getEmitter()->emit(new RequestEvent(RequestEvent::REFRESH_TOKEN_CLIENT_FAILED, $request));
throw OAuthServerException::invalidRefreshToken('Token is not linked to client');
}
to
if ($refreshTokenData['client_id'] != $clientId) {
$this->getEmitter()->emit(new RequestEvent(RequestEvent::REFRESH_TOKEN_CLIENT_FAILED, $request));
throw OAuthServerException::invalidRefreshToken('Token is not linked to client');
}
even though $clientId was matching, the function is passed a string (as required) but the $refreshTokenData['client_id'] is an integer.
fml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With