{"record":{"id":"9e7a7b7e97a04b29","repo":"siyuan-note/siyuan","slug":"load-github-user-failed-w","errorCode":null,"errorMessage":"load GitHub user failed: %w","messagePattern":"load GitHub user failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/oidc_provider/provider.go","lineNumber":162,"sourceCode":"\t\t\t},\n\t\t\tRedirectURL: redirectURL,\n\t\t\tScopes:      scopes,\n\t\t},\n\t}\n}\n\nfunc isDefaultOIDCScopes(scopes []string) bool {\n\tif len(scopes) != 3 {\n\t\treturn false\n\t}\n\treturn contains(scopes, oidc.ScopeOpenID) && contains(scopes, \"profile\") && contains(scopes, \"email\")\n}\n\nfunc exchangeGitHubClaims(ctx context.Context, token *oauth2.Token) (map[string]any, error) {\n\tclient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(token))\n\tuser := map[string]any{}\n\tif err := getGitHubJSON(ctx, client, \"https://api.github.com/user\", &user); err != nil {\n\t\treturn nil, fmt.Errorf(\"load GitHub user failed: %w\", err)\n\t}\n\tdelete(user, \"email\")\n\tif id, ok := user[\"id\"]; ok {\n\t\tuser[\"sub\"] = fmt.Sprint(id)\n\t}\n\temails := []struct {\n\t\tEmail    string `json:\"email\"`\n\t\tPrimary  bool   `json:\"primary\"`\n\t\tVerified bool   `json:\"verified\"`\n\t}{}\n\tif err := getGitHubJSON(ctx, client, \"https://api.github.com/user/emails\", &emails); err == nil {\n\t\tall := make([]string, 0, len(emails))\n\t\tfor _, email := range emails {\n\t\t\tif !email.Verified {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tall = append(all, email.Email)\n\t\t\tif email.Primary {","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/oidc_provider/provider.go#L144-L180","documentation":"exchangeGitHubClaims wraps any failure from the GET https://api.github.com/user request (network error, non-2xx status, or JSON decode failure) as \"load GitHub user failed: %w\". This is thrown while resolving OIDC claims via GitHub as the identity provider, so the OAuth/OIDC token exchange cannot produce a user identity.","triggerScenarios":"OAuth/OIDC sign-in flow where GitHub is the provider: Exchange -> exchangeGitHubClaims -> getGitHubJSON(https://api.github.com/user) fails because the access token is invalid/expired/revoked (401), the token lacks the user scope (404/403), GitHub rate limit (403 with rate limit headers), or network/DNS failure reaching api.github.com.","commonSituations":"Server cannot reach api.github.com (firewall, offline, proxy issues); user revoked the GitHub app authorization; misconfigured OAuth app client secret causing a bad token; GitHub API rate limiting on shared IPs (CI/self-hosted); GitHub API outage.","solutions":["Check the wrapped cause (%w) to see if it is a network error or the status code from error 1681","Verify the GitHub OAuth app ClientID/ClientSecret and that the authorization completed successfully","Test connectivity to api.github.com from the server (curl -H 'User-Agent: SiYuan' https://api.github.com/user with the token)","If rate limited (403), retry after the X-RateLimit-Reset time or use a different egress IP","Retry the sign-in to obtain a fresh access token"],"exampleFix":"// before: treat all GitHub failures identically\nif err := getGitHubJSON(ctx, client, \"https://api.github.com/user\", &user); err != nil {\n\treturn nil, fmt.Errorf(\"load GitHub user failed: %w\", err)\n}\n// after: distinguish rate limiting and auth failures for clearer messages\nif err := getGitHubJSON(ctx, client, \"https://api.github.com/user\", &user); err != nil {\n\tvar statusErr interface{ StatusCode() int }\n\tif errors.As(err, &statusErr) && statusErr.StatusCode() == 403 {\n\t\treturn nil, fmt.Errorf(\"GitHub API rate limited: %w\", err)\n\t}\n\treturn nil, fmt.Errorf(\"load GitHub user failed: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Go: probe the token before exchanging claims\nresp, err := http.Get(\"https://api.github.com/user\") // with Authorization header\nif err != nil || resp.StatusCode != 200 { /* surface connectivity/token problem early */ }","typeGuard":"func isNetworkErr(err error) bool {\n\tvar netErr net.Error\n\treturn errors.As(err, &netErr)\n}","tryCatchPattern":"user, err := exchangeGitHubClaims(ctx, token)\nif err != nil {\n\tif strings.Contains(err.Error(), \"status 403\") {\n\t\t// rate limited: back off and retry later\n\t} else {\n\t\t// log wrapped cause: fmt.Sprintf(\"%+v\", errors.Unwrap(err))\n\t}\n}","preventionTips":["Monitor GitHub API rate-limit headers when many users authenticate from one IP","Keep the OAuth app credentials and scopes up to date","Add alerting on repeated \"load GitHub user failed\" occurrences","Provide a fallback identity provider for GitHub outages"],"tags":["go","oauth","github-api","network"],"backgroundTag":"upstream-api-error","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"}