Skip to content

Google Auth fails for some users

谷歌验证对部分用户失败 #

🌐 Google Auth fails for some users

如果你开始遇到以下任何一个错误:

🌐 If you start facing either of these errors:

1
error=server_error&error_description=Error+getting+user+email+from+external+provider
2
3
Missing required authentication credential.
4
5
Expected OAuth 2 access token, login cookie or other valid authentication credential.
6
7
See https://developers.google.com/identity/sign-in/web/devconsole-project.\",\n \"status\": \"UNAUTHENTICATED\"
8
9
}
10
"level":"error","method":"GET","msg":"500: Error getting user email from external provider","path":"/callback","referer":"https://accounts.google.com/","remote_addr":"x.x.X.x","time":"2023-06-06T21:46:11Z","timestamp":"2023-06-06T21:46:11Z"}

这是因为某些 Google 套件需要明确请求电子邮件权限范围:https://www.googleapis.com/auth/userinfo.email

🌐 It is happening because some Google Suite requires the explicit request of email Auth Scopes: https://www.googleapis.com/auth/userinfo.email

1
const { data, error } = await supabase.auth.signInWithOAuth({
2
provider: 'google',
3
options: {
4
scopes: 'https://www.googleapis.com/auth/userinfo.email',
5
},
6
}
7
})