Repository navigation
Support OAuth 2.0 SAML 2.0 Bearer Assertion grant (RFC 7522) - #1
devin-ai-integration[bot] wants to merge 5 commits into
Conversation
Adds the urn:ietf:params:oauth:grant-type:saml2-bearer grant type to the token endpoint. Assertions must be signed by an enabled SAML identity provider of the realm, addressed to the token endpoint, carry a bearer subject confirmation, and are single-use. The subject is mapped to the user linked to that identity provider. Clients opt in via the oauth2.saml2.bearer.grant.enabled attribute. Signed-off-by: gk.raghavendra.gk <gk.raghavendra.gk@gmail.com> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
- Ignore link-only SAML identity providers - Evaluate required action triggers (e.g. verify email) before issuing tokens - Keep replay entries until the latest valid bearer confirmation expires, rounding up - Accept assertions addressed to the backend token endpoint URL Signed-off-by: gk.raghavendra.gk <gk.raghavendra.gk@gmail.com> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ntext Signed-off-by: gk.raghavendra.gk <gk.raghavendra.gk@gmail.com> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Note
Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.
Devin Review found 5 findings. Devin automatically fixed all 5 findings.
Fixed by Devin (5)
- Backchannel SAML grants reject valid assertions — Recipient and audience are validated against both frontend and backend token endpoint URLs; unit test added.
- Link-only providers can issue login tokens — Link-only SAML IdPs are now excluded from issuer lookup.
- Unevaluated email verification allows token issuance — Required action triggers are evaluated (as in the ROPC grant) and both user and auth-session required actions block issuance.
- Replay protection expires before assertion validity — Replay entry lifespan now uses the latest valid bearer confirmation expiry (capped by Conditions) and rounds up to whole seconds.
- Scope-based profile requirements bypassed — Scope client note and context auth session are now set before evaluating required action triggers, so scope-bound profile attributes are enforced.
End-to-end SAML bearer grant verification at
|
- Replace commons-lang3 StringUtils (not a services dependency) with Keycloak StringUtil - Pass the realm to getConsentByClient in UsernamePasswordForm and CookieAuthenticator (NPE with user cache) - JpaRealmProvider: drop duplicate session field, define TRANSFORMATION, import Base64 Signed-off-by: gk.raghavendra.gk <gk.raghavendra.gk@gmail.com> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Clean regression run at
|
Restores JpaRealmProvider to its state before 919fbd3; encryption is not required. Signed-off-by: gk.raghavendra.gk <gk.raghavendra.gk@gmail.com> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Client secret rotation verified at
|
Adds
grant_type=urn:ietf:params:oauth:grant-type:saml2-bearerto the OIDC token endpoint.Request:
grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer&assertion=<base64url SAML Assertion>, plus normal client authentication.Processing (
Saml2BearerGrantType/Saml2BearerAssertionValidator):oauth2.saml2.bearer.grant.enabled=true. A new Admin Console checkbox under Capability config sets it. Otherwise the request fails withunauthorized_client.<saml:Assertion>. ItsIssuermust match theidpEntityIdof exactly one enabled, non-link-only SAML identity provider in the realm.AudienceRestrictionmust contain the token endpoint (frontend or backend URL) or realm issuer URL.SubjectConfirmationwhoseRecipientis the token endpoint and whoseNotOnOrAfterhas not passed.Conditionsare enforced with the IdP's allowed clock skew.issuer:IDpair is stored inSingleUseObjectProvideruntil the assertion's latest valid expiry.OAuth2GrantTypeBase.createTokenResponse.invalid_grant(orinvalid_requestwhen the parameter is missing) and fire an event.Also:
grant_types_supportedin discovery, and the expected counts inAbstractWellKnownProviderTestare updated.OAuth2Constants, plus the attribute inOIDCConfigAttributes/OIDCAdvancedConfigWrapper.Fixes for pre-existing breakage on
main(requested to be included here):servicesdidn't compile:UsernamePasswordForm,ConditionalOtpFormAuthenticatorandCookieAuthenticatorusedorg.apache.commons.lang3.StringUtils, whichservicesdoesn't depend on. Replaced with Keycloak'sorg.keycloak.utils.StringUtiland a plainindexOfforsubstringBefore; no new dependency.UsernamePasswordFormandCookieAuthenticatorcalledgetConsentByClient(null, ...). They now pass the current realm.model/jpadidn't compile because of an incomplete client-secret encryption customization inJpaRealmProvider(commit919fbd3798). Encryption isn't required, soJpaRealmProvideris restored to its state before that commit. The rest of that commit is unchanged.Testing:
Saml2BearerAssertionValidatorTesthas 13 unit tests (valid assertion, realm-issuer audience, standard base64, backend token endpoint, unsigned, wrong key, tampered, expired, wrong or missing audience, wrong recipient, non-bearer confirmation, non-assertion document). All pass. End-to-end runs against a locally built server passed. The SAML grant was tested with the Admin Console toggle and real signed assertions (success, replay, tampered, untrusted, disabled client). A later clean build without workarounds also passed: login with the user cache enabled, the grant plus replay, and a new client's client_credentials. See the PR comments.Link to Devin session: https://app.devin.ai/sessions/6329efa8c1364cf5abf704442c263bc1
Open in Devin Desktop: https://app.devin.ai/desktop/session/6329efa8c1364cf5abf704442c263bc1?variant=devin
Requested by: @RaghavGK
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work