Closed shawnz closed 3 months ago
An additional note: the specification for token introspection, RFC 7662, doesn't actually say client authentication is necessary for token introspection. But, it does say that some kind of authentication is necessary, and suggests client authentication as one possible option. However, in its current state, this library only supports client authentication and not any other possible authentication system for token introspection.
I didn't make any effort to fix that here, I simply added validation to make sure that the client secret is correct (since it was already required to be present with the existing logic anyway).
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: