Google授权页仅请求邮箱SSO权限,未显示日历权限求助
无论我进行何种操作,Google授权页始终无法显示Google Calendar权限请求。当前处于测试模式,使用测试用户,但仍无法解决该问题。相关代码如下:
async function handleSignInWithGoogle(response) { const nonce = await generateNonce(); const { data, error } = await supabase.auth.signInWithIdToken({ provider: 'google', token: response.credential, nonce: nonce, options: { scopes: ['openid', 'profile', 'email', 'https://www.googleapis.com/auth/calendar.readonly'] } }); if (error) { console.error('Error signing in:', error.message); } else { email = data.user?.email ?? ''; accessToken = data.session?.access_token; console.log('Access Token:', accessToken); } loading = false; }
const handleGoogleLogin = async () => { loading = true; const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'google', options: { scopes: ['openid', 'profile', 'email', 'https://www.googleapis.com/auth/calendar.readonly'] } }); if (error) { console.error('Error signing in:', error.message); } else { email = data.user.email; } loading is false; };
可能的原因及解决方法
Google Cloud控制台配置遗漏
确认Google Cloud的OAuth 2.0客户端ID设置中,已将https://www.googleapis.com/auth/calendar.readonly添加到授权范围,同时测试用户已正确加入OAuth同意屏幕的测试用户列表。另外检查OAuth同意屏幕状态为“测试中”,且测试用户未超出数量限制。Supabase Auth的Scope传递逻辑错误
signInWithIdToken方法是基于第三方ID Token完成认证,Scope参数需要在前端Google登录组件(比如Google One Tap、Google Sign-In按钮)初始化时指定,而非在Supabase的该方法中传递。
对于signInWithOAuth方法,需确认Supabase控制台的Google OAuth配置(Auth -> Providers -> Google)中,客户端ID、密钥填写正确,无配置遗漏。测试用户已提前授权
若测试用户之前已授予过该日历权限,Google会跳过权限请求页。可让用户进入Google账号安全设置,移除当前应用的授权记录后重新登录测试。代码语法错误
第二个函数handleGoogleLogin末尾的loading is false;是语法错误,需改为loading = false;,该错误可能导致流程异常,先修复后再测试。
内容的提问来源于stack exchange,提问作者J Badger

