I'm developing a react app. Google OAuth 2.0 login works on the web version. However, on Android (Expo Go), I constantly encounter the error:
Access blocked:
Authorization Error.
Error 400: invalid_request
Request details:
redirect_uri=exp://192.168.50.36:8081
flowName=GeneralOAuthFlow
In the android client settings (Google Cloud Console):
- the SHA-1 is correct,
- the package name is "host.exp.exponent" (specific to Expo Go).
In .env: all the Client IDs are written.
I've already tried using useProxy, but it didn't work. I've also tried configuring redirectURI, but it didn't work either.
Below is a key piece of code from the login.tsx file (after this piece of code, you will be redirected to the welcome page, so it doesn't matter.):
import { View } from "react-native";
import { Button, Card, Screen, Text } from "@/shared/ui";
import { spacing } from "@/shared/theme";
import { useEffect } from "react";
import * as Google from 'expo-auth-session/providers/google';
import * as WebBrowser from 'expo-web-browser';
import { storage } from '@/shared/storage';
import { useAppData } from "@/features/app-data/app-data-provider";
import { router } from "expo-router";
WebBrowser.maybeCompleteAuthSession();
export default function LoginScreen() {
const { setUser, session } = useAppData();
const [request, response, promptAsync] = Google.useAuthRequest({
webClientId: process.env.EXPO_PUBLIC_GOOGLE_WEB_CLIENT_ID,
androidClientId: process.env.EXPO_PUBLIC_GOOGLE_ANDROID_CLIENT_ID,
scopes: ['profile', 'email'],
});
(..other code...)
}
the issue with useProxy not working is that it is deprecated, now you are supposed to use deepLinks. What you have to do is declare your scheme name in your app.json and whitelist it inside your google cloud console ( something like com.yourname.appname )
There's more about it in their docs like right here about AuthSession and there is a guide aswell. Hope it helps.
P.S.: If you test your app in Expo Go application, not sure it works, you might need to switch to development build instead.
Hevix