Skip to content

Commit da1d931

Browse files
[server] fix private GitHub avatars (#20461)
* [server] fix private GitHub avatars * Improve comment and don't delete all search params
1 parent 3e570ae commit da1d931

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

components/server/src/github/github-auth-provider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ export class GitHubAuthProvider extends GenericAuthProvider {
9999
data: { id, login, avatar_url, name, company, created_at },
100100
headers,
101101
} = currentUser;
102+
const publicAvatarURL = new URL(avatar_url);
103+
if (publicAvatarURL.host === "private-avatars.githubusercontent.com") {
104+
// github has recently been rolling out private JWT-signed avatar URLs which expire after a short time
105+
// we need to use the public avatar URL instead so that the avatar is displayed correctly and fits into our database column (which is capped at 255 chars)
106+
publicAvatarURL.host = "avatars.githubusercontent.com";
107+
publicAvatarURL.searchParams.delete("jwt");
108+
}
102109

103110
// https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/
104111
// e.g. X-OAuth-Scopes: repo, user
@@ -125,7 +132,7 @@ export class GitHubAuthProvider extends GenericAuthProvider {
125132
authUser: {
126133
authId: String(id),
127134
authName: login,
128-
avatarUrl: avatar_url,
135+
avatarUrl: publicAvatarURL.toString(),
129136
name,
130137
primaryEmail: filterPrimaryEmail(userEmails),
131138
company,

0 commit comments

Comments
 (0)