`expo-auth-session` и `expo-auth-session/providers/google`.
Среда:
– React Native (Expo Router)
– Работа в Expo Go на iOS
– клиент Google OAuth Идентификаторы, созданные в Google Cloud:
- Веб-приложение
- iOS
- Android
Код: Выделить всё
import { AntDesign } from '@expo/vector-icons';Код: Выделить всё
import AsyncStorage from '@react-native-async-storage/async-storage';Код: Выделить всё
import * as Google from 'expo-auth-session/providers/google';Код: Выделить всё
import { useRouter } from 'expo-router';Код: Выделить всё
import * as WebBrowser from 'expo-web-browser';Код: Выделить всё
import React, { useCallback, useEffect, useState } from 'react';Код: Выделить всё
import { Alert, Button, Pressable, Text, View } from 'react-native';Код: Выделить всё
import IconFacebook from '../../../icons/IconFacebook';Код: Выделить всё
import IconGoogle from '../../../icons/IconGoogle';Код: Выделить всё
WebBrowser.maybeCompleteAuthSession();Код: Выделить всё
export default function LoginScreen() {Код: Выделить всё
const router = useRouter();Код: Выделить всё
const [, setUserInfo] = useState(null);Код: Выделить всё
const redirectUri = 'https://auth.expo.io/@trieuman2705/bkoo';Код: Выделить всё
const [request, response, promptAsync] = Google.useAuthRequest({Код: Выделить всё
expoClientId:Код: Выделить всё
'8263....apps.googleusercontent.com',Код: Выделить всё
iosClientId:Код: Выделить всё
'8263...apps.googleusercontent.com',Код: Выделить всё
androidClientId:Код: Выделить всё
'8263332....apps.googleusercontent.com',Код: Выделить всё
webClientId:Код: Выделить всё
'8263332....apps.googleusercontent.com',Код: Выделить всё
scopes: ['profile', 'email'],Код: Выделить всё
redirectUri,Код: Выделить всё
});Код: Выделить всё
useEffect(() => {Код: Выделить всё
console.log('Google redirectUri =', request?.redirectUri);Код: Выделить всё
}, [request]);Код: Выделить всё
// ...fetchUserInfo + UI omitted for brevityКод: Выделить всё
}Код: Выделить всё
'8263332....apps.googleusercontent.com'Код: Выделить всё
https://auth.expo.io/@trieuman2705/bkooОднако, когда я запускаю поток входа в систему и регистрирую сгенерированный запрос, я вижу следующее:
Код: Выделить всё
OAuth Request: {Код: Выделить всё
redirectUri: "https://auth.expo.io/@trieuman2705/bkoo",Код: Выделить всё
request: {Код: Выделить всё
clientId: "826333210617-dogrjmu5121isqo1gdnblogr23j6qh6b.apps.googleusercontent.com", //
Подробнее здесь: [url]https://stackoverflow.com/questions/79833457/expo-google-oauth-with-expo-auth-session-redirect-uri-mismatch-and-flowname-gen[/url]
Мобильная версия