In our app when user logs out we invalidate the access token for that particular device this way.
$user = $request->user(); $value = $request->bearerToken(); $id = (new Parser())->parse($value)->getHeader('jti'); $token = $user->tokens->find($id); $token->revoke();
But when an user deactivates his/her account, we would like to invalidate all the access tokens from all the devices the user is logged in. I looked through the document but did not find anything useful. Thanks
You may revoke a token by using the revokeAccessToken method on the Laravel\Passport\TokenRepository .
If you don't want to use the Passport middleware in the project where you want to validate the tokens, you would have to create an endpoint in the Laravel Passport server that can accept the token, perform the usual Passport validation and return a response to your service.
The "tymondesigns/jwt-auth" is a PHP Laravel implementation of the JWT protocol. On the other hand, Passport also uses JWT by default plus a huge extra, a complete Oauth2 implementation. Regarding the functionality, as I said they both use JWT thus you can use whichever you like to authentication via tokens.
To revoke a refresh token, send a POST request to https://YOUR_DOMAIN/oauth/revoke . The /oauth/revoke endpoint revokes the entire grant, not just a specific token. Use the /api/v2/device-credentials endpoint to revoke refresh tokens.
Take a look at the HasApiTokens
trait provided by passport. The documentation recommends adding this trait to your User model. One of the methods it provides is tokens()
, which defines a hasMany
relationship between Laravel\Passport\Token
and models using the trait. You can use this to retrieve a list of all of the tokens for a given user:
$userTokens = $userInstance->tokens;
The token model itself has a revoke
method:
foreach($userTokens as $token) { $token->revoke(); }
This worked for ME:
use Laravel\Passport\Token; Token::where('user_id', $user->id) ->update(['revoked' => true]);
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