Support token revocation and introspection#1473
Support token revocation and introspection#1473hafezdivandari wants to merge 29 commits intothephpleague:masterfrom
Conversation
|
@Sephster , as mentioned #1453 (comment), it would be great to have more maintainers for this repository! @hafezdivandari is an excellent professional with extensive knowledge of OAuth2. Having more people to support the project would certainly help its growth and maintenance! 🚀 |
|
Hi @Sephster, by any chance, did you have the time to check this PR? I'd appreciate any comments or feedback. |
|
Sorry I hadn't realised it was ready for review. I'll get to it as soon as I can but am going to clear some outstanding issues prior. Thanks for your work on this |
|
@Sephster thanks so much for all your work maintaining this library! I was just wondering whether you had even a rough idea of when you might get to looking at this PR? It would be super helpful for the problem I'm currently trying to solve! 😅 |
|
Hey @Sephster, I feel the OAuth Server is a bit incomplete without this. When you have a chance, could you take a look? The PR is large, but I did my best to make it easy to review. It’s also difficult to keep it open for too long since other merged PRs may cause conflicts. Thanks. |
|
I'll be picking this up next. Thanks |
|
Thanks @Sephster! I have the implementation PR ready for Laravel Passport if you’d like to see it in action: laravel/passport#1858 |
|
I'm on holiday with the family for a few days but still reviewing and hoping to get a first response to you soon. Thanks for the patience |
|
Hey @Sephster Any updates on this one? |
|
Was working on this last night. There are quite a few aspects to this so it is taking a while. I have two RFCs I need to check for compliance, significant architecture changes, and tagged issues I need to ensure are satisfied. It is a big review but am quietly plugging away on it. I'm going to try dedicate an evening to it soon |
Sephster
left a comment
There was a problem hiding this comment.
Sorry for the lengthy time with this @hafezdivandari - there was a lot to go through but here is my first pass. Apologies that there are quite a lot of comments but that comes with the extent of the changes I guess. Thanks for all your effort on this.
|
Hi @Sephster, thank you for reviewing the PR and for the detailed feedback. I’ve addressed the requested changes and replied to each comment. Please feel free to resolve any comment where you find my response satisfactory. |
|
Hi @Sephster , would there be any chance of having this merged as a Christmas gift? |
|
That's my intention but my kids gifts are going to have to take priority 🐵 I aim to have this reviewed before Christmas though, all being well. Thanks @hafezdivandari |
|
Aiming to pick up and complete this this week @hafezdivandari - thanks for your patience |
|
Hi @Sephster , any progress? |
|
Not yet - was working on dropping PHP 8.1 support last week but aim to pick this up, at least partially, this evening all being wel |
Fixes #806
Fixes #1350
Closes #1255
Closes #1135
Closes #995
Closes #925
It's much easier to implement Token Revocation RFC7009 and Token Introspection RFC7662 at the same time! These 2 RFCs have most of the logic in common:
"application/x-www-form-urlencoded" data:
tokenis required, accepts either an access token or a refresh token.token_type_hintis optional to help the server optimize the token lookup.access_tokenorrefresh_token.Authorization: Basic {client_credentials}headerclient_idandclient_secretparameters.400:invalid_requestthe requiredtokenparameter was not sent.401:invalid_clientthe request is not authorized. Client credentials were not sent or invalid.200: The token is revoked, expired, doesn't exists, or was not issued to the client making the request:activefield set tofalse.{ "active": false }200: The token is valid, active, and was issued to the client making the request:activefield set totrue.{ "active": true, ... }Implementation
Summary
Summary of file changes in order of appearance.
New
AbstractHandlerclassAbstractGrantandAbstractTokenHandlerclasses.clientRepository,accessTokenRepository, andrefreshTokenRepositoryproperties have been moved to this class from childAbstractGrantclass.setClientRepository,setAccessTokenRepository,setRefreshTokenRepository,getClientCredentials,parseParam,getRequestParameter,getBasicAuthCredentials,getQueryStringParameter,getCookieParameter,getServerParameter, andvalidateEncryptedRefreshTokenmethods have been moved to this class from childAbstractGrantclass without any change.validateClientmethod from childAbstractGranthas been moved to this class with a minor change: The call togetIdentifier()isGrantTypeInterfacespecific.getClientEntityOrFailmethod from childAbstractGranthas been moved to this class. This method is also overridden on childAbstractGrant: Call tosupportsGrantTypemethod isAbstracGrantspecific.validateEncryptedRefreshTokenis extracted fromRefreshTokenGrant::validateOldRefreshTokenmethod.Change
AuthorizationValidators\BearerTokenValidatorclassBearerTokenValidatorInterfaceinterface.validateAuthorizationmethod into a newvalidateBearerTokenmethod.validateBearerTokenmethod also accepts optional$clientIdargument. If a$clientIdis provided, it verifies whether the token was issued to the given client.New
AuthorizationValidators\BearerTokenValidatorInterfaceinterfaceBearerTokenValidatorclass.validateBearerTokenmethod.AbstractTokenHandler::setBearerTokenValidator()method.Change
Exception\OAuthServerExceptionclassunsupportedTokenTypemethod.Change
Grant\AbstractGrantclassAbstractHandlerclass.AbstractHandlerclass.getClientEntityOrFailmethod.Change
Grant\RefreshTokenGrantclassvalidateOldRefreshTokenmethod has been extracted into a new parent AbstractHandler::validateEncryptedRefreshToken method.New
Handlers\AbstractTokenHandlerclassAbstractHandlerclass.TokenHandlerInterfaceinterface.setPublicKeyandsetBearerTokenValidatormethods that to allow injecting a customized token validator.validateToken,validateAccessTokenandvalidateRefreshTokenmethods that have been used byTokenIntrospectionHandlerandTokenRevocationHandlerclasses.New
Handlers\TokenHandlerInterfaceinterfaceAbstractTokenHandlerclass.setTokenRevocationHandlerandsetTokenIntrospectionHandlermethods of theTokenServerclass.New
Handlers\TokenIntrospectionHandlerclassAbstractTokenHandlerclass.respondToRequestmethod that responds to "Token Introspection RFC7662" request.setResponseTypemethod that allows injecting a customized response type.New
Handlers\TokenRevocationHandlerclassAbstractTokenHandlerclass.respondToRequestmethod that responds to "Token Revocation RFC7009" request.New
ResponseTypes\IntrospectionResponseclassIntrospectionResponseTypeInterfaceinterface.generateHttpResponsemethod to generate "Token Revocation RFC7009" response.New
ResponseTypes\IntrospectionResponseTypeInterfaceclassIntrospectionResponseclass.TokenIntrospectionHandler::setResponseTypemethod that allows injecting a customized response type.New
TokenServerclassrespondToTokenRevocationRequestandrespondToTokenIntrospectionRequestmethods to respond to the respective request.setTokenRevocationHandlerandsetTokenIntrospectionHandlermethods that allows injecting customized handlers.