Skip to content

fix: handle email_verified as JSON string or boolean in OidcUser#502

Open
shoichi1023 wants to merge 3 commits intolejianwen:masterfrom
shoichi1023:fix/oidc-email-verified-type-mismatch
Open

fix: handle email_verified as JSON string or boolean in OidcUser#502
shoichi1023 wants to merge 3 commits intolejianwen:masterfrom
shoichi1023:fix/oidc-email-verified-type-mismatch

Conversation

@shoichi1023
Copy link
Copy Markdown

Problem

Some OIDC providers (e.g. Amazon Cognito) return email_verified as a JSON string ("true"/"false") instead of a JSON boolean, which violates OIDC Core spec section 5.1.

This caused the following error at login:

failed decoding user info: json: cannot unmarshal string into Go struct field OidcUser.email_verified of type bool

Fix

Change OidcUser.VerifiedEmail from bool to json.RawMessage, which accepts any JSON value without type errors. Then normalize both representations using strings.EqualFold + strings.Trim to handle:

  • JSON boolean: true / false
  • JSON string: "true" / "false" / "True" / "TRUE" (case-insensitive)
  • null or absent field → defaults to false

Tests

Added model/oauth_test.go covering all the above cases.

kawachi added 3 commits March 6, 2026 16:08
Some OIDC providers such as Amazon Cognito return the email_verified
claim as a JSON string ("true"/"false") instead of a JSON boolean,
which violates the OIDC Core spec (section 5.1).

Change VerifiedEmail field type from bool to json.RawMessage and use
strings.Trim to normalize both representations before comparison.
… for email_verified

- Use strings.EqualFold to handle "True"/"TRUE" from non-standard providers
- Document nil/absent field behavior (defaults to false) in comment
- Add oauth_test.go covering bool, string, case-insensitive, null, and absent cases
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