Fix token introspection and revocation authentication checks #93
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes two issues I noticed with the token introspection and revocation endpoints:
Neither endpoint actually checks to make sure that the client secret provided is actually correct, only that one is provided.
The revoke token endpoint fails if a client secret is not provided, even if the client is a public client that doesn't have a client secret. The RFC 7009 specification seems to imply that public clients should be allowed to revoke tokens in section 2.1 "Revocation Request":
https://www.rfc-editor.org/rfc/rfc7009.html#section-2.1
Note how only in the case of a confidential client is it necessary to validate client credentials. So public clients should not have their credentials validated (since they don't have any).
One thing that's not exactly clear, is how should public clients provide their client ID to the endpoint if they don't use the authorization header? In RFC 7009 the section 2.1 "Revocation Request" doesn't indicate the presence of any
client_id
field in the request body for this purpose. However, later on in section 5 "Security Considerations" they imply that aclient_id
field in the request body actually is the right way to do it after all:https://www.rfc-editor.org/rfc/rfc7009.html#section-5
The ability to read from the
client_id
field in the request body is already supported byget_client_credentials
, so no change was required to implement that.This PR fixes the first issue by adding calls to
storage.get_client
, which validates the secret.The second issue is fixed by adding a new parameter to the
get_client_credentials
function,secret_required
, which is set toFalse
for the revoke token endpoint. This new parameter is also used to simplify some of the logic in thecreate_token_response
function, which previously used a complicated try/except block to achieve the same thing.Some tests are also added to ensure the new functionality works.
Before making the change:
After making the change: