Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] fix private GitHub avatars #20461

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion components/server/src/github/github-auth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ export class GitHubAuthProvider extends GenericAuthProvider {
data: { id, login, avatar_url, name, company, created_at },
headers,
} = currentUser;
const publicAvatarURL = new URL(avatar_url);
if (publicAvatarURL.host === "private-avatars.githubusercontent.com") {
// github has recently been rolling out private JWT-signed avatar URLs which expire after a short time
// we need to use the public avatar URL instead so that the avatar is displayed correctly and fits into our database (which is capped at 255 chars)
publicAvatarURL.host = "avatars.githubusercontent.com";
publicAvatarURL.search = "";
}

// https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/
// e.g. X-OAuth-Scopes: repo, user
Expand All @@ -125,7 +132,7 @@ export class GitHubAuthProvider extends GenericAuthProvider {
authUser: {
authId: String(id),
authName: login,
avatarUrl: avatar_url,
avatarUrl: publicAvatarURL.toString(),
name,
primaryEmail: filterPrimaryEmail(userEmails),
company,
Expand Down
Loading