You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo Go React Native谷歌登录遇Access Blocked授权错误求助

解决Expo React Native谷歌登录OAuth 2.0安全策略错误

问题描述

启动浏览器触发谷歌登录错误:
Access blocked: Authorization error. You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy for keeping apps secure.

用户提供的实现代码:

import React, { useState, useEffect } from "react";
import {
  View,
  Button,
} from "react-native";

import * as Google from 'expo-auth-session/providers/google'
export default function LoginBox({ navigation }) {
    const [accessToken, setAccessToken] = React.useState();

    const [request, response, promptAsync] = Google.useAuthRequest({
        expoClientId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com',
        iosClientId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com',
    })


    useEffect (() => {
        if (response?.type === 'success') {
            setAccessToken(response.authentication.accessToken)
        }
    }, [response])

    const getUserData = () => {
        
    }

  return (
    <View style={{backgroundColor: 'white'}}>

    <Button title={accessToken ? "Get User Data": "Login"}
        onPress={accessToken ? getUserData : () => promptAsync({useProxy: 'true', showInRecents: 'true' })}
    />
      
    </View>
  );
}

排查与解决步骤

1. 修正重定向URI和授权源配置

  • 登录Google Cloud控制台,找到对应OAuth客户端ID:
    • 确保已授权的重定向URI精确匹配:https://auth.expo.io/@你的用户名/你的项目Slug,注意用户名和项目Slug完全一致,大小写敏感
    • 确认已授权的JavaScript源包含https://auth.expo.io,不要添加多余路径或拼写错误

2. 核对客户端ID类型

  • expoClientId必须对应Web应用类型的客户端ID,iosClientId对应iOS类型客户端ID,两者不能混用
  • 确保两个客户端ID都归属同一个Google Cloud项目,且已启用Google Identity API(在API库中搜索启用)

3. 修正promptAsync参数类型

代码中useProxy和showInRecents传了字符串'true',需改为布尔值true,否则会导致代理流程异常:

onPress={accessToken ? getUserData : () => promptAsync({useProxy: true, showInRecents: true })}

4. 处理应用验证与测试用户

  • 开发阶段:在OAuth同意屏幕设置中,添加测试邮箱账号,测试用户可绕过安全拦截正常登录
  • 生产阶段:需完成Google应用验证流程,提交应用详情、隐私政策链接等信息,通过验证后解除登录限制

内容的提问来源于stack exchange,提问作者ShiGame

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 18:55:19