{"record":{"id":"883e080598474c19","repo":"siyuan-note/siyuan","slug":"decode-oidc-claims-failed-w","errorCode":null,"errorMessage":"decode OIDC claims failed: %w","messagePattern":"decode OIDC claims failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/oidc_provider/provider.go","lineNumber":112,"sourceCode":"\t\treturn nil, fmt.Errorf(\"exchange OIDC authorization code failed: %w\", err)\n\t}\n\tif p.kind == conf.OIDCProviderGitHub {\n\t\treturn exchangeGitHubClaims(ctx, token)\n\t}\n\trawIDToken, ok := token.Extra(\"id_token\").(string)\n\tif !ok || rawIDToken == \"\" {\n\t\treturn nil, errors.New(\"OIDC response does not contain an ID token\")\n\t}\n\tidToken, err := p.verifier.Verify(ctx, rawIDToken)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"verify OIDC ID token failed: %w\", err)\n\t}\n\tif idToken.Nonce != nonce {\n\t\treturn nil, errors.New(\"OIDC nonce does not match\")\n\t}\n\tclaims := map[string]any{}\n\tif err = idToken.Claims(&claims); err != nil {\n\t\treturn nil, fmt.Errorf(\"decode OIDC claims failed: %w\", err)\n\t}\n\treturn claims, nil\n}\n\nfunc newGitHub(config *conf.OIDC, redirectURL string) *Provider {\n\tscopes := append([]string{}, config.Scopes...)\n\tif len(scopes) == 0 || isDefaultOIDCScopes(scopes) {\n\t\tscopes = []string{\"read:user\", \"user:email\"}\n\t} else {\n\t\tfiltered := scopes[:0]\n\t\tfor _, scope := range scopes {\n\t\t\tif scope != oidc.ScopeOpenID && scope != \"profile\" && scope != \"email\" {\n\t\t\t\tfiltered = append(filtered, scope)\n\t\t\t}\n\t\t}\n\t\tscopes = filtered\n\t\tif !contains(scopes, \"read:user\") {\n\t\t\tscopes = append([]string{\"read:user\"}, scopes...)","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/oidc_provider/provider.go#L94-L130","documentation":"After verifying the ID token, Exchange decodes its claims into a map[string]any via idToken.Claims(&claims); a decoding failure (unexpected claim types the JSON decoder cannot unmarshal, malformed payload) is wrapped as \"decode OIDC claims failed\". The token was cryptographically valid but its claim payload could not be materialized for the caller.","triggerScenarios":"Calling Exchange when idToken.Claims fails to decode the verified token's JSON payload into map[string]any — e.g. a claim value with a type the decoder rejects, or a corrupted/abnormal token payload from a non-conformant IdP.","commonSituations":"IdPs emitting exotic claim values (very large numbers, nested structures conflicting with the target type); middleware rewriting tokens; malformed JSON in tokens from non-conformant providers; rarely, library/version incompatibilities in claim handling.","solutions":["Inspect the ID token payload (jwt.io or equivalent) to find which claim breaks decoding, then adjust IdP claim configuration (e.g. fix a custom claim's type).","Update/align the OIDC library versions on both sides if a claim-type incompatibility is suspected.","Log the wrapped cause and report the non-conformant IdP behavior; work around by normalizing claims at the IdP (e.g. Keycloak mapper) to standard JSON types.","Retry the sign-in with a different account/issuer to confirm whether the problem is account-specific claim data."],"exampleFix":"// before\nclaims := map[string]any{}\nif err = idToken.Claims(&claims); err != nil {\n    return nil, fmt.Errorf(\"decode OIDC claims failed: %w\", err) // diagnosing: dump token payload\n}\n// after\nclaims := map[string]any{}\nif err = idToken.Claims(&claims); err != nil {\n    // inspect raw token: log rawIDToken payload (never the secret) to find the offending claim,\n    // then fix the IdP claim mapper to emit standard JSON types\n    return nil, fmt.Errorf(\"decode OIDC claims failed: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"parts := strings.Split(rawIDToken, \".\")\nif len(parts) != 3 {\n    return errors.New(\"ID token is not a well-formed JWT\")\n}","typeGuard":null,"tryCatchPattern":"claims, err := provider.Exchange(ctx, code, verifier, nonce)\nif err != nil {\n    if strings.Contains(err.Error(), \"decode OIDC claims failed\") {\n        // inspect the token payload and the IdP claim mappers; report non-conformant claim types\n    }\n    return err\n}","preventionTips":["Configure IdP custom-claim mappers to emit standard JSON types","Test the IdP with a standards-compliant client before production rollout","Keep OIDC library versions current to benefit from decoder fixes"],"tags":["oidc","jwt","json","claims"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}