最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google oauth 2.0 invalid_request:400 with expo android app - Stack Overflow

programmeradmin2浏览0评论

Its my first time doing Oauth authentication with expo, and im only running the app on android and when i try to authenticate with google i get the following 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.

also from the documentation i dont understand at all what should be the redirect_uri and thats probably the problem, i cant find an absolute answer of what should be the redirect_uri

thats my code:

import React, { useEffect, useState } from "react";
import { Button, Text, View } from "react-native";
import * as AuthSession from "expo-auth-session";
import * as Google from "expo-auth-session/providers/google";
import * as SecureStore from "expo-secure-store";

export default function App() {
  const [user, setUser] = useState(null);

  const [request, response, promptAsync] = Google.useAuthRequest({
    androidClientId: process.env.EXPO_PUBLIC_ANDROID_GOOGLE_CLIENT_ID,
    selectAccount: true, 
    redirectUri: "com.anonymous.pystart://oauth2redirect"
  });
  
  

  useEffect(() => {
    if (response?.type === "success") {
      const { authentication } = response;
      handleLogin(authentication?.accessToken);
    }
  }, [response]);

  async function handleLogin(token: string | undefined) {
    const userInfoResponse = await fetch(
      ";,
      {
        headers: { Authorization: `Bearer ${token}` },
      }
    );
    const userInfo = await userInfoResponse.json();
    setUser(userInfo);
    await SecureStore.setItemAsync("userToken", token);
  }

  return (
    <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
      {user ? (
        <Text>Welcome, {user.name}</Text>
      ) : (
        <Button
          title="Sign in with Google"
          disabled={!request}
          onPress={() => promptAsync()}
        />
      )}
    </View>
  );
}

发布评论

评论列表(0)

  1. 暂无评论