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

Expo React Native集成Clerk Google OAuth遇政策合规错误求解决

Expo React Native集成Clerk Google认证触发“不符合Google政策”错误排查

我在Expo React Native应用中集成Clerk认证,实现Google Auth注册功能,但触发了**“Clerk request does not comply with google policy”**错误。已在Clerk控制台配置相关令牌,但问题仍未解决。

错误截图:
Android模拟器上的错误提示

以下是我的实现代码:

WebBrowser.maybeCompleteAuthSession()

enum Strategy {
    Google = 'oauth_google',
    Apple = 'oauth_apple',
    Facebook = 'oauth_facebook'
}

export default function Page() {
    useWarmUpBrowser();

    const router = useRouter()

    const { startOAuthFlow: appleAuth } = useOAuth({ strategy: 'oauth_apple' })
    const { startOAuthFlow: googleAuth } = useOAuth({ strategy: 'oauth_google' })
    const { startOAuthFlow: facebookAuth } = useOAuth({ strategy: 'oauth_facebook' })

    // 选择认证方式
    const onSelectAuth = async (strategy: Strategy) => {
        const selectedAuth = {
            [Strategy.Google]: googleAuth,
            [Strategy.Apple]: appleAuth,
            [Strategy.Facebook]: facebookAuth
        }[strategy];

        try {
            const {createdSessionId , setActive} = await selectedAuth()

            if(createdSessionId){
                setActive!({session:createdSessionId})
                router.back()
            }
        } catch (error) {
            console.error('OAuth error', error)
        }
    }

    return (
        <View style={styles.container}>
            <TextInput autoCapitalize='none' placeholder='email' style={[defaultStyles.inputField, { marginBottom: 30 }]} />
            <TouchableOpacity style={defaultStyles.btn}>
                <Text style={defaultStyles.btnText}>Continue</Text>
            </TouchableOpacity>
            <View style={styles.separatorView}>
                <View style={{
                    flex: 1,
                    borderBottomColor: '#000',
                    borderBottomWidth: StyleSheet.hairlineWidth,
                }} />

                <Text style={styles.separator}>or</Text>
                <View style={{
                    flex: 1,
                    borderBottomColor: '#000',
                    borderBottomWidth: StyleSheet.hairlineWidth,
                }} />
            </View>
            <View style={{ gap: 20 }}>
                <TouchableOpacity style={styles.btnOutline}>
                    <Ionicons size={24} name='call-outline' style={defaultStyles.btnIcon} />
                    <Text style={styles.btnOutlineText}>Continue with phone</Text>
                </TouchableOpacity>
                <TouchableOpacity onPress={() => onSelectAuth(Strategy.Apple)} style={styles.btnOutline}>
                    <Ionicons size={24} name='md-logo-apple' style={defaultStyles.btnIcon} />
                    <Text style={styles.btnOutlineText}>Continue with Apple</Text>
                </TouchableOpacity>
                <TouchableOpacity onPress={() => onSelectAuth(Strategy.Google)} style={styles.btnOutline}>
                    <Ionicons size={24} name='md-logo-google' style={defaultStyles.btnIcon} />
                    <Text style={styles.btnOutlineText}>Continue with google</Text>
                </TouchableOpacity>
                <TouchableOpacity onPress={() => onSelectAuth(Strategy.Facebook)} style={styles.btnOutline}>
                    <Ionicons size={24} name='md-logo-facebook' style={defaultStyles.btnIcon} />
                    <Text style={styles.btnOutlineText}>Continue with Facebook</Text>
                </TouchableOpacity>
            </View>
        </View>
    )
}

解决步骤

  • 检查Google Cloud OAuth配置
    • 确保OAuth 2.0客户端ID的授权重定向URI与Clerk控制台配置一致,格式通常为https://<你的Clerk域名>/oauth/google/callback。
    • 确认OAuth consent screen已完成配置:填写正确的应用名称、隐私政策链接,测试环境需添加测试用户,生产环境需发布应用。
    • 启用Google身份验证相关API(如Google+ API)。
  • 核对Clerk控制台配置
    • 确认Google Client ID和Client Secret与Google Cloud生成的完全一致,无拼写错误。
    • 检查Clerk OAuth设置中的环境(开发/生产)与当前应用环境匹配。
  • Expo应用配置检查
    • 在app.json或app.config.js中配置正确的scheme:
      {
        "expo": {
          "scheme": "your-app-scheme"
        }
      }
      
    • 确保WebBrowser.maybeCompleteAuthSession()在App组件最顶部调用,早于任何路由渲染。
  • 代码调整
    • 调用useOAuth时显式指定redirectUri:
      const { startOAuthFlow: googleAuth } = useOAuth({ 
        strategy: 'oauth_google',
        redirectUri: 'https://你的Clerk域名/oauth/google/callback'
      })
      
    • 若为测试环境,确认已将测试用户添加到Google OAuth consent screen中,避免未验证应用的访问限制。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 11:15:22