Skip to content

broker: use /userinfo as fallback for claims not available in id token#1476

Open
shiv-tyagi wants to merge 1 commit intocanonical:mainfrom
shiv-tyagi:fix/oidc-email-verified
Open

broker: use /userinfo as fallback for claims not available in id token#1476
shiv-tyagi wants to merge 1 commit intocanonical:mainfrom
shiv-tyagi:fix/oidc-email-verified

Conversation

@shiv-tyagi
Copy link
Copy Markdown
Contributor

@shiv-tyagi shiv-tyagi commented Apr 18, 2026

Fixes #1440.

This uses the information retrieved from /userinfo endpoint as a fallback for claims not available in id token.

This only affects the generic oidc broker, for msentraid, we simple drop the information retrieved from /userinfo.

I have verified both oidc and msentraid brokers with these changes, they both work fine.

Fixes [canonical#1440](canonical#1440).

This uses the information retrieved from /userinfo endpoint as a fallback for claims not available in id token.

This only affects the generic oidc broker, for ms entra id, we simple drop the information retrieved from /userinfo.

I have verified both oidc and msentraid brokers with these changes, they both work fine.

Signed-off-by: Shiv Tyagi <shivtyagi3015@gmail.com>
@shiv-tyagi shiv-tyagi force-pushed the fix/oidc-email-verified branch from 7fcdce8 to 94176c9 Compare April 18, 2026 12:41
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

❌ Patch coverage is 84.37500% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.42%. Comparing base (1f7d986) to head (94176c9).

Files with missing lines Patch % Lines
...ernal/providers/genericprovider/genericprovider.go 82.60% 4 Missing ⚠️
authd-oidc-brokers/internal/broker/broker.go 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1476      +/-   ##
==========================================
- Coverage   86.94%   80.42%   -6.52%     
==========================================
  Files          93       20      -73     
  Lines        6366     1073    -5293     
  Branches      111        0     -111     
==========================================
- Hits         5535      863    -4672     
+ Misses        775      210     -565     
+ Partials       56        0      -56     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +1176 to 1184
oidcUserInfo, err := session.oidcServer.UserInfo(ctx, oauth2.StaticTokenSource(token))
if err != nil {
log.Warningf(ctx, "could not fetch information from /userinfo endpoint: %v", err)
}

userInfo, err := b.provider.GetUserInfo(idToken, oidcUserInfo)
if err != nil {
return info.User{}, err
}
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.

The UserInfo request is one more network request which can go wrong, and it's not needed in most cases, so I think we should not do it unconditionally but only if the ID token is actually missing a required claim. I would implement it like this:

  1. First, call b.provider.GetUserInfo(idToken)
  2. If the ID token misses a required claim, GetUserInfo should return a MissingClaimError
  3. If it does, we fetch the claims from the UserInfo endpoint and merge them with the ones from the ID token into a single claims struct and then call b.provider.GetUserInfo(claims)

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.

Issue: okta does not include email_verified claim in ID token

2 participants