Skip to content

fix(oidc): unified discovery + optional endpoint overrides#170

Merged
coopernetes merged 1 commit into
mainfrom
fix/oidc-config
Apr 16, 2026
Merged

fix(oidc): unified discovery + optional endpoint overrides#170
coopernetes merged 1 commit into
mainfrom
fix/oidc-config

Conversation

@coopernetes
Copy link
Copy Markdown
Member

Summary

  • Replaces the if jwk-set-uri / else dual-path ClientRegistration logic in SecurityConfig with a single path: always run OIDC discovery via ClientRegistrations.fromIssuerLocation(), then apply any non-blank override properties (authorization-uri, token-uri, user-info-uri, jwk-set-uri) on top
  • Adds authorizationUri to OidcAuthConfig to complete the set of overridable endpoint properties
  • Updates userInfoUri javadoc to document the Entra ID Graph endpoint problem: OIDC discovery for Entra points to graph.microsoft.com/oidc/userinfo which omits preferred_username; fix is to set user-info-uri to https://login.microsoftonline.com/{tenant}/v2.0/userinfo

Motivation

The manual path was originally added to work around Entra ID v1.0 issuer mismatches (iss=https://sts.windows.net/{tenant}/), but it hardcoded endpoint URLs as {issuerUri}/authorize, {issuerUri}/token, {issuerUri}/userinfo — which are wrong for Entra and any provider with non-standard paths. With Entra ID v2.0 (/{tenant}/v2.0 issuer), the discovery document's issuer field matches the configured issuer-uri, so ClientRegistrations.fromIssuerLocation() works directly and the manual bypass is no longer needed.

Test plan

  • Local OIDC provider (mock or Keycloak) login flow succeeds with no overrides set
  • Entra ID login succeeds with user-info-uri override set to https://login.microsoftonline.com/{tenant}/v2.0/userinfo and user-name-attribute: preferred_username
  • preferred_username is populated in the authenticated principal
  • Group-based role mapping works with groups-claim: groups

🤖 Generated with Claude Code

…ptional overrides

Previously, SecurityConfig had two ClientRegistration paths gated on
jwk-set-uri: a fully-manual path (hardcoding {issuerUri}/authorize,
/token, /userinfo) and a discovery path that applied no overrides at
all. The manual path was added to work around Entra ID v1.0 issuer
mismatches but hardcoded endpoint URLs that are wrong for Entra (and
any other provider with non-standard paths).

With Entra ID v2.0 (/{tenant}/v2.0 issuer), the discovery document's
issuer field matches the configured issuer-uri, so the startup
assertion in ClientRegistrations passes cleanly and the manual bypass
is no longer needed.

Replace both paths with a single path that always runs OIDC discovery
via ClientRegistrations.fromIssuerLocation(), then applies any
non-blank override properties (authorization-uri, token-uri,
user-info-uri, jwk-set-uri) on top. This is idiomatic Spring Security
and keeps the code generic across providers.

Add authorizationUri to OidcAuthConfig to complete the set of
overridable endpoint properties. Update userInfoUri javadoc to document
the Entra-specific Graph endpoint problem and its fix (set user-info-uri
to login.microsoftonline.com/{tenant}/v2.0/userinfo to get
preferred_username in the UserInfo response).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coopernetes coopernetes enabled auto-merge (squash) April 16, 2026 18:21
@coopernetes coopernetes merged commit 13d693f into main Apr 16, 2026
11 checks passed
@coopernetes coopernetes deleted the fix/oidc-config branch April 16, 2026 18:21
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