mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
Fix STACK-BACKEND-6V
This commit is contained in:
parent
21454eb23a
commit
5824eae0a6
@ -30,16 +30,37 @@ export class GithubProvider extends OAuthBaseProvider {
|
||||
}
|
||||
|
||||
async postProcessUserInfo(tokenSet: TokenSet): Promise<OAuthUserInfo> {
|
||||
const rawUserInfo = await this.oauthClient.userinfo(tokenSet.accessToken);
|
||||
|
||||
const emails = await fetch("https://api.github.com/user/emails", {
|
||||
const rawUserInfoRes = await fetch("https://api.github.com/user", {
|
||||
headers: {
|
||||
Authorization: `token ${tokenSet.accessToken}`,
|
||||
},
|
||||
}).then((res) => res.json());
|
||||
if (!emails.find) {
|
||||
throw new StackAssertionError("Error fetching user emails from github", {
|
||||
});
|
||||
if (!rawUserInfoRes.ok) {
|
||||
throw new StackAssertionError("Error fetching user info from GitHub provider: Status code " + rawUserInfoRes.status, {
|
||||
rawUserInfoRes,
|
||||
hasAccessToken: !!tokenSet.accessToken,
|
||||
hasRefreshToken: !!tokenSet.refreshToken,
|
||||
accessTokenExpiredAt: tokenSet.accessTokenExpiredAt,
|
||||
});
|
||||
}
|
||||
const rawUserInfo = await rawUserInfoRes.json();
|
||||
|
||||
const emailsRes = await fetch("https://api.github.com/user/emails", {
|
||||
headers: {
|
||||
Authorization: `token ${tokenSet.accessToken}`,
|
||||
},
|
||||
});
|
||||
if (!emailsRes.ok) {
|
||||
throw new StackAssertionError("Error fetching user emails from GitHub: Status code " + emailsRes.status, {
|
||||
emailsRes,
|
||||
rawUserInfo,
|
||||
});
|
||||
}
|
||||
const emails = await emailsRes.json();
|
||||
if (!Array.isArray(emails)) {
|
||||
throw new StackAssertionError("Error fetching user emails from GitHub: Invalid response", {
|
||||
emails,
|
||||
emailsRes,
|
||||
rawUserInfo,
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user