Fix UserInfo: use real email_verified, gate claims by scope#50
Merged
Conversation
Two OIDC Core spec violations in the /oauth/userinfo endpoint: 1. email_verified was hardcoded to true instead of using the actual value from the JWT claims (which correctly reflects the DB state). New users with unverified emails were incorrectly reported as verified. 2. email and email_verified were returned unconditionally regardless of requested scopes. Per OIDC Core Section 5.4, these require the "email" scope. Similarly, username is now gated by the "profile" scope. Also fixes TestUserInfoEndpoint which was masking bug #1 by asserting email_verified=true (which only passed due to the hardcoded value), and adds TestUserInfoScopeGating to verify claims are properly gated. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace strings.Contains with slices.Contains for scope membership checks in UserInfo to avoid substring false positives (e.g. a hypothetical "noemail" scope matching "email"). Add TestUserInfoEmailScopeOnly to verify that requesting "openid email" returns email claims but not profile claims. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- UserInfo endpoint description now documents scope-gated claims - Token endpoint description no longer mentions id_token (not yet implemented, tracked in #52) - Regenerated swagger docs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/oauth/userinfowas hardcodingemail_verified: trueinstead of using the actual value from the JWT (which correctly reflects the DB). Unverified users were reported as verified.emailandemail_verifiedare now only returned when theemailscope is requested, andusernameis only returned whenprofilescope is requested, per OIDC Core Section 5.4.TestUserInfoEndpointnow correctly assertsemail_verified=falsefor new unverified users (previously passed only because of the hardcoded bug).TestUserInfoScopeGatingverifies that claims are absent when their corresponding scope is not requested.Test plan
go build ./...passesgo vet ./...passesopenid profile email)🤖 Generated with Claude Code