OAuth TokenHandler Enhancement: Authorization Header Fallback Support #1316
+582
−2
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.
OAuth TokenHandler Enhancement: Authorization Header Fallback Support
This PR implements the enhancement requested in issue #1315 to add fallback support for OAuth client credentials in the Authorization header when they are missing from the request form data. This improves OAuth 2.0 compliance by supporting both
client_secret_post
andclient_secret_basic
authentication methods.Changes Made
Fixes #1315
This PR adds fallback support for OAuth client credentials in the Authorization header when they are missing from the request form data. The TokenHandler now checks for Basic authentication in the Authorization header as a fallback, improving OAuth 2.0 compliance by supporting both client_secret_post and client_secret_basic methods.
Motivation and Context
Currently, the TokenHandler only looks for client credentials in the request form data. However, according to OAuth 2.0 specifications, client credentials can also be provided in the Authorization header using Basic authentication. When credentials are only provided in the header, the handler throws a ValidationError even though valid credentials are present. This enhancement addresses this limitation by implementing a fallback mechanism.
How Has This Been Tested?
Comprehensive tests have been added covering:
All new tests pass (7/7) and existing tests continue to pass. Code passes linting (ruff) and type checking (pyright).
Breaking Changes
None. This is a purely additive enhancement that maintains 100% backward compatibility. Existing OAuth clients using form data authentication will continue to work exactly as before.
Types of changes
Checklist
Additional context
The implementation follows OAuth 2.0 best practices and maintains the security model while improving flexibility for different client implementations. It's particularly useful for web applications, mobile apps, and enterprise integrations that prefer using Basic authentication headers. The enhancement is non-intrusive and only activates when credentials are missing from form data, ensuring minimal performance impact.