Postponed
Project:
Simple OAuth (OAuth2) & OpenID Connect
Version:
6.1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
16 Feb 2018 at 10:12 UTC
Updated:
2 Jan 2026 at 09:18 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
skdrupal88Comment #3
skdrupal88Comment #4
e0ipsoHello! Thanks for dropping by.
You will need to use Entity Query to find the tokens associated with the user and delete those entities.
Comment #5
e0ipsoComment #6
spleshkaHi @e0ipso,
Would you agree that it worth having the endpoint in OAuth to revoke the token? It feels like quite a security measure to be able to expire access and refresh tokens from remote.
(Setting the issue state to Active, since I believe it may require additional discussion / further dev actioning).
Comment #7
e0ipso@Spleshka would you be able to do it with REST or JSON API? You can PATCH or DELETE the token entities, right?
Comment #8
ndobromirov commentedI am pretty sure it's responsibility of this module. Exposing the tokens form another module sounds like breaking the standard for that: https://tools.ietf.org/html/rfc7009
Comment #9
e0ipso@ndobromirov that's a good point. However what I mean is: "the feature is not supported at the moment, but you can work around that with other modules. If that fits your use case, then great."
That being said, I'll be happy to review a patch that implements spec-compliant token revocation.
Comment #10
e0ipsoComment #11
arnoldbird commented"You will need to use Entity Query to find the tokens associated with the user and delete those entities."
This does not appear to be possible, because tokens are not associated with users in the database. All tokens are associated with an anonymous (zero) UID.
There must be some way, programmatically, to log a user out. I see that saving a user's account has the effect of invalidating (deleting?) their access token, so perhaps I just need to figure out where that happens in Drupal's code and then copy that approach.
In the meantime, does anyone have a solution to support a "Log out" button in an app? Can someone give me a hint? : )
Thanks
Comment #12
e0ipsoTake a look at the https://cgit.drupalcode.org/simple_oauth/tree/src/ExpiredCollector.php for more info on how that is accomplished.
Comment #13
arnoldbird commentedThe collectForAccount method in that class seems to assume we can look up a user's tokens by the 'auth_user_id'. However, that column is always zero in the database.
Is there something I need to do so that, when the token is created, it gets associated with a Drupal UID? Is it normal for auth_user_id.oauth2_token to always be zero? I figure this is either something I'm doing wrong in my /oauth/token call, or it's an incomplete implementation in simple_oauth.
Comment #14
berdir@e0ipso: The problem is that only works for *access tokens*, refresh tokens have no uid so it is impossible to identify them.
That said, a Log out button in the app should be easy, you just forget about the tokens in the app. they won't be cleaned up on the server but you will be logged out.
Comment #15
e0ipsoYes, that was a response to:
Comment #16
arnoldbird commentedApologies! I just looked at my oauth2_token table and I see that the auth_user_id value is indeed set to the user ID for access tokens. I was wrong when I said...
I swear I sorted on that column forward and back and could not find anything but zeros yesterday, but I must have missed it somehow.
Now that I see the auth_user_id column has the user ID in it, this becomes an easy problem to solve.
Comment #17
jyoti.singh commentedCan we have a endpoint to revoke the access token and the refresh token to make it generic.For example, if we have a headless system where the drupal endpoints are consumed by angular framework, we need to have a endpoint to revoke the tokens.
Comment #18
e0ipsoI think that what we need first is a patch to add the user identifier to the refresh tokens: #2974963: Link refresh tokens to the user they will identidy for query filtering
Comment #19
e0ipsoComment #20
jyoti.singh commentedThe action to revoke all the access token should be done on the logout.
Comment #21
ayalon commentedI created a patch for this issue here:
https://www.drupal.org/project/simple_oauth/issues/2974963
Feel free to test it.
Comment #22
e0ipsoWe still want this. Bubbling it up.
Comment #23
briangonzalezmia@e0ipso Yes, please! #22
Comment #24
e0ipsoJust to be 💯 clear, I don't have plans to work on this. I was bubbling it up in #22 so anyone else could pick it up. I hope you understand.
Comment #25
matt_paz commentedShould this be closed now that #2974963 has been committed or are there other things in here #2974963 didn't resolve?
Comment #26
robertom commented@matt_paz this issue is still valid.
I've found this issue on oauth2-server that could be useful.
Comment #27
robertom commentedComment #28
robertom commentedHi, sorry for my bad english.
I need to logout from an angular frontend and, at the same time, log out also from the drupal backend (I use drupal also as the Authentication Server for the Authorization code flow ).
I added two routes (only on POST):
- /oauth/revoke (revoke all access_token and refresh_token for the current user)
- /oauth/logout (same as /oauht/revoke but remove also session for the current user)
The /oauth/revoke isn't fully compliant with the RFC7009, but remove the tokens :D
This patch REQUIRE also the patch from comment #50 #2946882-50: Auth revoke on profile update otherwise it would not remove the refresh tokens.
Comment #29
robertom commented@e0ipso I know it's not the implementation required in the summary, but what do you think as a "temporary" solution?
Comment #30
robertom commentedComment #31
jainv18 commented@robertom -- Thanks for writing this patch. Much needed.
Can you please help me with the headers for invoking /oauth/logout -- for example, withCredentials: True or Authorization header etc.
Also, I assume that if we use the endpoint 'oauth/logout', it will also delete the cookie and ends the authentication of User.
Comment #32
harishst+1 for the patch @robertom. I have used this in my custom module for creating Logout API.
Comment #33
kevishie commentedIs there anything holding this up? Seems like an OAuth implementation should have a revoke endpoint.
Comment #34
kevishie commentedFixed @robertom's patch for 5.x
Comment #35
kevishie commentedAfter looking at this code more, the revoke endpoint should follow the RFC spec and take a token and token_type_hint parameter. This patch tries to get the current logged in user ($this->currentUser()) but in a headless, stateless API this wouldn't return a user.
Comment #36
bradjones1Bumping major versions and linking related issue.
Comment #37
pq commentedTrying out this patch, I'm finding that using the revoke endpoint, access tokens are getting deleted but refresh tokens are not. It looks like this is because
ExpiredCollector->collectForAccount()adds the condition$query->condition('bundle', 'refresh_token', '!=');(in 5.2 at least).The patch passes a second parameter
TRUEtoExpiredCollector->collectForAccount(), but this doesn't appear to do anything. Was the intention for that parameter to be something like$include_refresh_tokensand to bypass the condition if set toTRUE?Comment #38
pq commentedAh sorry, just read #28.
Ignore me. :)
Comment #39
realityloop commentedpatch against 6.x
Comment #40
mediabounds commentedIf it's helpful to others, we recently updated the Simple OAuth Revoke module which just adds the
/oauth/revokeroute as outlined by the RFC 7009.(Note: The patch in this issue also adds an
/oauth/logoutendpoint; that's not part of the RFC 7009 spec so it's not in the Simple OAuth Revoke module.)Comment #41
berenddeboer commentedTo add to this long chain: here a merge request for the simple_oauth_revoke module that adds support for 6.x-dev and makes the module compatible with Drupal 11: https://www.drupal.org/project/simple_oauth_revoke/issues/3541068#commen...
Comment #42
bojan_dev commentedI don’t want to add any new features to versions of
simple_oauthbelow6.0. I see that there has been good progress inthephpleague/oauth2-serverto support this feature: https://github.com/thephpleague/oauth2-server/pull/1473. Once it’s merged, we can start implementing it in version 6.1.x, including full test coverage.