8000 Set default Bearer token_type in broker token responses by atiqur-rahman-pro · Pull Request #53995 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Set default Bearer token_type in broker token responses - #53995

Merged
pedroigor merged 1 commit into
keycloak:mainfrom
atiqur-rahman-pro:fix/broker-token-response-token-type-53954
Oct 15, 2026
Merged

pedroigor merged 1 commit into
keycloak:mainfrom
atiqur-rahman-pro:fix/broker-token-response-token-type-53954

Conversation

@atiqur-rahman-pro
Copy link
Copy Markdown
Contributor

Closes #53954

Summary of Changes

  1. Default Bearer token_type fallback:
    • In AbstractIdentityProvider.buildTokenResponse(...), ensure tokenResponse.getTokenType() falls back to TokenUtil.TOKEN_TYPE_BEARER ("Bearer") if missing, conforming to RFC 6749 §5.1 and RFC 8693 §2.2.1.
  2. Preserve custom/non-Bearer token types:
    • In AbstractOAuth2IdentityProvider, preserve external IdP custom token types (e.g. DPoP) across stored token exchanges (exchangeStoredToken), session-backed token exchanges (exchangeSessionToken), and refresh token requests (refreshToken).
    • Store and retrieve FEDERATED_TOKEN_TYPE in user session notes to maintain token type consistency across session lifetimes.
  3. Standard OIDC Login Propagation:
    • In OIDCIdentityProvider.extractIdentityFromProfile(...) and GitLabIdentityProvider.extractIdentityFromProfile(...), populate FEDERATED_TOKEN_TYPE into identity context data during standard login so that broker V2 endpoints preserve the IdP's token type.
  4. Test Coverage:
    • Added unit tests in AbstractOAuth2IdentityProviderTest covering token type serialization, fallback from dynamic claims, and default Bearer handling.
    • Added integration test assertions in OAuth2IdentityProviderStoreTokenV2Test and IdentityProviderStoreTokenV2Test verifying standard login note propagation and custom token type preservation.
    • Updated integration Arquillian tests (KcOidcBrokerTokenExchangeTest, SocialLoginTest) for legacy token exchange assertions.

Copilot AI balanced review requested due to automatic review settings October 15, 2026 07:01
@atiqur-rahman-pro
atiqur-rahman-pro requested review from a team as code owners October 15, 2026 07:01
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Token-type handling still loses explicit values in supported flows, can retain stale session values, and rejects valid capitalization in a test.

4 open findings
What changed in this PR

Addresses #53954 by adding a default Bearer token type to broker responses while preserving explicit identity-provider token types.

Changes:

  • Adds token-type propagation through login, storage, sessions, and refresh.
  • Adds unit and integration coverage for fallback and preservation behavior.
  • Extends legacy token-exchange assertions.
File Description
testsuite/​integration-arquillian/​tests/​base/​src/​test/​java/​org/​keycloak/​testsuite/​broker/​SocialLoginTest.java Adds social token-type assertions.
testsuite/​integration-arquillian/​tests/​base/​src/​test/​java/​org/​keycloak/​testsuite/​broker/​KcOidcBrokerTokenExchangeTest.java Adds legacy exchange assertions.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​broker/​OAuth2IdentityProviderStoreTokenV2Test.java Tests fallback and custom-type preservation.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​broker/​IdentityProviderStoreTokenV2Test.java Tests OIDC session-note propagation.
services/​src/​test/​java/​org/​keycloak/​test/​broker/​oidc/​AbstractOAuth2IdentityProviderTest.java Tests serialization and response defaults.
services/​src/​main/​java/​org/​keycloak/​social/​gitlab/​GitLabIdentityProvider.java Propagates GitLab token types.
services/​src/​main/​java/​org/​keycloak/​broker/​oidc/​OIDCIdentityProvider.java Propagates OIDC token types.
services/​src/​main/​java/​org/​keycloak/​broker/​oidc/​AbstractOAuth2IdentityProvider.java Carries token types through storage, sessions, and refresh.
server-spi-private/​src/​main/​java/​org/​keycloak/​broker/​provider/​AbstractIdentityProvider.java Defaults missing token types to Bearer.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

10BC8
Copilot AI balanced review requested due to automatic review settings October 15, 2026 07:30
@atiqur-rahman-pro
atiqur-rahman-pro force-pushed the fix/broker-token-response-token-type-53954 branch from e7f0a3a to 9c3c986 Compare October 15, 2026 07:30
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fallback and propagation changes have regression coverage, with no blocking issues identified in static review.

0 open findings

4 resolved since last review

🧠 Review effort: Balanced

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Form-response parsing can 6870 return encoded values or select the wrong parameter as the token type.

1 open finding

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 15, 2026 09:07
@atiqur-rahman-pro
atiqur-rahman-pro force-pushed the fix/broker-token-response-token-type-53954 branch from 8d3dbb9 to c1d54d4 Compare October 15, 2026 09:07
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused changes preserve explicit token types and provide the required fallback, with no blocking issues identified; automated tests were not executed.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@pedroigor pedroigor left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @atiqur-rahman-pro.

In addition to the inline comments: why do we need to consider DPoP (or any non-Bearer token type) in brokering at all? The broker never sends a DPoP proof to the upstream IdP, so a compliant IdP will always issue Bearer, and Keycloak would have no key to use a DPoP-bound token anyway.

Closes keycloak#53954

Signed-off-by: Atiqur Rahman <rahman.atiqur.pro@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 15, 2026 12:00
@atiqur-rahman-pro
atiqur-rahman-pro force-pushed the fix/broker-token-response-token-type-53954 branch from c1d54d4 to 57cc591 Compare October 15, 2026 12:00
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Exchange paths discard upstream token types, causing the new fallback to mislabel non-Bearer tokens.

1 open finding

🧠 Review effort: Balanced

@atiqur-rahman-pro
Copy link
Copy Markdown
Contributor Author

Hi @pedroigor,

Thanks for the clarification. I’ve simplified the PR accordingly. It now only defaults a missing token_type to Bearer in buildTokenResponse(), with focused regression coverage for the V1 and V2 flows. I removed the token-type session state, custom token propagation, and related parsing logic. Could you please take another look?

@pedroigor
pedroigor enabled auto-merge (rebase) October 15, 2026 13:52
@pedroigor
Copy link
Copy Markdown
Contributor

Thanks, @atiqur-rahman-pro.

@pedroigor
pedroigor merged commit 9ad98e7 into keycloak:main Oct 15, 2026
156 of 159 checks passed
@atiqur-rahman-pro
atiqur-rahman-pro deleted the fix/broker-token-response-token-type-53954 branch October 15, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Identity Brokering API V2: /broker/{alias}/token response is missing the required token_type

3 participants

0