oauth2-server icon indicating copy to clipboard operation
oauth2-server copied to clipboard

Token Revocation question

Open chervand opened this issue 7 years ago • 13 comments

Are you going to include something RFC7009 compliant to the lib that could be used in a straightforward way like $server->respondToRevokeTokenRequest($request, $response);?

chervand avatar Oct 31 '17 18:10 chervand

I think it would be good to work towards this so would hope for it to be included in the future. Thanks for the suggestion

Sephster avatar Oct 31 '17 22:10 Sephster

I might try working on this for my own purposes. I can try to submit a PR if you want.

I could add a respondToRevokeTokenRequest method to AuthorizationServer. It would need to duplicate some of the code in AbstractGrant->validateClient, since that's not available to AuthorizationServer.

Then, depending on the token_type_hint, it would call either accessTokenRepository->revokeAccessToken or refreshTokenRepository->revokeRefreshToken. You'd probably need to pass the refresh token repository into the method, since it's not otherwise available to AuthorizationServer.

I think we'd also want to pass in a flag for whether to revoke the access token, when token_type_hint=refresh_token, since this is optional.

jacobweber avatar Feb 04 '19 19:02 jacobweber

I could add a respondToRevokeTokenRequest method to AuthorizationServer. It would need to duplicate some of the code in AbstractGrant->validateClient, since that's not available to AuthorizationServer.

@jacobweber if you are going to submit a PR try to avoid code duplication and try to decouple the validatClient feature if that is being duplicated. Maybe even submit a differnt PR if neccessary to get this right.

just my 0.002 cents ;-)

lordrhodos avatar Feb 04 '19 21:02 lordrhodos

Sure, if you don’t mind me moving that out of the Grant classes, and maybe into its own class, I can take that approach.

jacobweber avatar Feb 04 '19 21:02 jacobweber

Before I go ahead with writing tests and submitting a pull request, could I ask if this is something you're interested in at all, and if my approach in this commit is reasonable? It's based on master.

Basically I did this:

  • Copied the client validation code from AbstractGrant into a ClientValidator class (later I can separate this into its own PR, and change the Grants to use this same class).
  • Added a RevokeTokenHandler class to handle revoke requests. It checks to see if the token is an access or refresh token, and revokes it if possible. If $canRevokeAccessTokens is true, it will allow you to revoke access tokens, and it will revoke the associated access token when you revoke a refresh token.
  • Added a enableRevokeTokenHandler method to AuthorizationServer, which can be used like this:
$refreshTokenRepository = [...];
$authServer = new \League\OAuth2\Server\AuthorizationServer([...]);
$handler = new \League\OAuth2\Server\RevokeTokenHandler($refreshTokenRepository);
$authServer->enableRevokeTokenHandler($handler);
  • Added a respondToRevokeTokenRequest method to AuthorizationServer, which can be used in the same way as respondToAccessTokenRequest.

jacobweber avatar Feb 06 '19 21:02 jacobweber

Hi @jacobweber - this is definitely something I would like to add to the server so please feel free to submit a PR. Thanks!

Sephster avatar Feb 07 '19 09:02 Sephster

Hi @Sephster @jacobweber. I've already done it for the Yii2 framework integration library. In case you might want it here, I'll submit a PR.

chervand avatar Feb 07 '19 09:02 chervand

@Sephster Do you have a preferred approach? I won’t be offended if it’s not mine 😊. @chervand is using a new Grant, and I’m using a non-Grant class.

jacobweber avatar Feb 07 '19 15:02 jacobweber

Thanks both for your offers of help with this. I think that Jacob's proposal would be more likely to be accepted. If my understanding of the RFC is correct, this change is adding an endpoint rather than a grant. Thanks both again for your offers of help here.

Sephster avatar Feb 07 '19 15:02 Sephster

No problem. I will try to work it up into a PR. I may steal some of @chervand's more mature code if he doesn't mind.

jacobweber avatar Feb 07 '19 17:02 jacobweber

@jacobweber I don't mind :)

chervand avatar Feb 07 '19 17:02 chervand

It's been a while, still I think that revoking the tokens should be part of this library (because it's pure pain to handle it outside of the library).

The big question is: can we resurrect #995 or do we need an entirely new implementation?

filecage avatar Jan 02 '24 18:01 filecage

Probably can rectify. V9 is priority just now though. Then probably custom claims.

Sephster avatar Jan 02 '24 20:01 Sephster