Oauth2-server: Token Revocation question

Created on 31 Oct 2017  路  11Comments  路  Source: thephpleague/oauth2-server

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

Improvement Idea

All 11 comments

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

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.

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 ;-)

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

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.

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

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.

@Sephster Do you have a preferred approach? I won鈥檛 be offended if it鈥檚 not mine 馃槉. @chervand is using a new Grant, and I鈥檓 using a non-Grant class.

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.

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 I don't mind :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

delboy1978uk picture delboy1978uk  路  4Comments

stuartlangridge picture stuartlangridge  路  3Comments

Sephster picture Sephster  路  3Comments

alexfpoole picture alexfpoole  路  5Comments

airguillaume picture airguillaume  路  7Comments