访问被阻止:授权错误 - Expo Go React Native

问题描述 投票:0回答:1

我一直在尝试在我的 React Native 应用程序上设置使用 google 登录,并且在每次启动网络浏览器时实现下面的代码后,Google 网络浏览器都会生成错误:

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>
  );
}

我认为问题可能出在我的重定向 URI 上,即 https://auth.expo.io/@myusername/myslug,我授权的 JavaScript 来源是 https://auth.expo.io,但是我不确定。

react-native expo google-oauth
1个回答
0
投票
const EXPO_REDIRECT_PARAMS = {
    useProxy: true,
    projectNameForProxy: `@username/<YOURSCHEME>`
};

const NATIVE_REDIRECT_PARAMS = { native: '<YOURSCHEME>://' };
const REDIRECT_PARAMS =
    Constants.appOwnership === 'expo'
        ? EXPO_REDIRECT_PARAMS
        : NATIVE_REDIRECT_PARAMS;

const [request, response, promptAsync] = Google.useAuthRequest({
        expoClientId: GOOGLE_EXPO_CLIENT_ID,
        webClientId: WEB_CLIENT_ID,
        iosClientId: IOS_CLIENT_ID,
        scopes: ['profile', 'email'],
        redirectUri: makeRedirectUri(REDIRECT_PARAMS),
    });

同样重要的是,您的方案与 app.json 中的包标识符具有相同的名称。

© www.soinside.com 2019 - 2024. All rights reserved.