Skip to content

Canonicalize OAuth Bearer scheme when building Authorization header#1

Merged
mkazia merged 1 commit intomainfrom
oauth_bearer_fix
May 4, 2026
Merged

Canonicalize OAuth Bearer scheme when building Authorization header#1
mkazia merged 1 commit intomainfrom
oauth_bearer_fix

Conversation

@mkazia
Copy link
Copy Markdown
Owner

@mkazia mkazia commented May 4, 2026

Summary

  • Identity providers may return token_type in any case (e.g. bearer, BEARER) per RFC 6749/6750, but some downstream servers and proxies reject anything other than the canonical Bearer. This caused intermittent auth failures depending on the IdP's response casing.
  • Adds Token.getCanonicalTokenType(), which returns "Bearer" whenever tokenType case-insensitively matches "bearer" and otherwise returns the original value untouched.
  • Routes the three Authorization header construction sites through the new helper: OAuthHeaderFactory.fromTokenSource, AzureCliCredentialsProvider, and ServingEndpointsDataPlaneImpl. Non-Bearer schemes (e.g. MAC, custom) are unchanged.

Test plan

  • TokenTest.canonicalTokenTypeNormalizesBearerCasing — covers Bearer / bearer / BEARER / BeArEr all canonicalize to Bearer
  • TokenTest.canonicalTokenTypePreservesNonBearerSchemesCustom and MAC pass through unchanged
  • OAuthHeaderFactoryTest parameterized cases assert Authorization: Bearer <token> regardless of input casing; existing Custom case still passes (regression guard against over-canonicalization)
  • mvn -pl databricks-sdk-java -am clean test -Dtest='TokenTest,OAuthHeaderFactoryTest' — 12 passed

This pull request and its description were written by Isaac.

Identity providers may return token_type in any case (e.g. "bearer", "BEARER")
per RFC 6749/6750, but some downstream servers and proxies reject anything
other than the canonical "Bearer". Add Token.getCanonicalTokenType() and route
the three Authorization-header construction sites (OAuthHeaderFactory,
AzureCliCredentialsProvider, ServingEndpointsDataPlaneImpl) through it.
Non-Bearer schemes pass through unchanged.

Co-authored-by: Isaac
@mkazia mkazia merged commit 13f0eb5 into main May 4, 2026
@mkazia mkazia deleted the oauth_bearer_fix branch May 4, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant