siyuan-note/siyuan · error

load GitHub user failed

Error message

load GitHub user failed: %w

What it means

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.

Solutions

  1. Check the wrapped cause (%w) to see if it is a network error or the status code from error 1681
  2. Verify the GitHub OAuth app ClientID/ClientSecret and that the authorization completed successfully
  3. Test connectivity to api.github.com from the server (curl -H 'User-Agent: SiYuan' https://api.github.com/user with the token)
  4. If rate limited (403), retry after the X-RateLimit-Reset time or use a different egress IP
  5. Retry the sign-in to obtain a fresh access token

Example fix

// before: treat all GitHub failures identically
if err := getGitHubJSON(ctx, client, "https://api.github.com/user", &user); err != nil {
	return nil, fmt.Errorf("load GitHub user failed: %w", err)
}
// after: distinguish rate limiting and auth failures for clearer messages
if err := getGitHubJSON(ctx, client, "https://api.github.com/user", &user); err != nil {
	var statusErr interface{ StatusCode() int }
	if errors.As(err, &statusErr) && statusErr.StatusCode() == 403 {
		return nil, fmt.Errorf("GitHub API rate limited: %w", err)
	}
	return nil, fmt.Errorf("load GitHub user failed: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: probe the token before exchanging claims
resp, err := http.Get("https://api.github.com/user") // with Authorization header
if err != nil || resp.StatusCode != 200 { /* surface connectivity/token problem early */ }

Type guard

func isNetworkErr(err error) bool {
	var netErr net.Error
	return errors.As(err, &netErr)
}

Try / catch

user, err := exchangeGitHubClaims(ctx, token)
if err != nil {
	if strings.Contains(err.Error(), "status 403") {
		// rate limited: back off and retry later
	} else {
		// log wrapped cause: fmt.Sprintf("%+v", errors.Unwrap(err))
	}
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/9e7a7b7e97a04b29. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/oidc_provider/provider.go:162

			},
			RedirectURL: redirectURL,
			Scopes:      scopes,
		},
	}
}

func isDefaultOIDCScopes(scopes []string) bool {
	if len(scopes) != 3 {
		return false
	}
	return contains(scopes, oidc.ScopeOpenID) && contains(scopes, "profile") && contains(scopes, "email")
}

func exchangeGitHubClaims(ctx context.Context, token *oauth2.Token) (map[string]any, error) {
	client := oauth2.NewClient(ctx, oauth2.StaticTokenSource(token))
	user := map[string]any{}
	if err := getGitHubJSON(ctx, client, "https://api.github.com/user", &user); err != nil {
		return nil, fmt.Errorf("load GitHub user failed: %w", err)
	}
	delete(user, "email")
	if id, ok := user["id"]; ok {
		user["sub"] = fmt.Sprint(id)
	}
	emails := []struct {
		Email    string `json:"email"`
		Primary  bool   `json:"primary"`
		Verified bool   `json:"verified"`
	}{}
	if err := getGitHubJSON(ctx, client, "https://api.github.com/user/emails", &emails); err == nil {
		all := make([]string, 0, len(emails))
		for _, email := range emails {
			if !email.Verified {
				continue
			}
			all = append(all, email.Email)
			if email.Primary {

View on GitHub (pinned to 9f775e8a12)