【发布时间】:2021-02-10 01:43:12
【问题描述】:
我希望有人可以帮助我解决我一直在努力解决的以下问题。
我正在尝试在 Expo SDK 39 中在 Android 上使用 expo-auth-session/providers/google 进行 Google 身份验证。
我已按照指南 here 进行操作,但我所做的一切都以谷歌消息告终:
错误 400:invalid_request redirect_uri 的参数值无效: 无效方案:com.my_domain.myapp:/oauthredirect
我就是不明白我做错了什么。
我需要提到一个事实,即在 Expo Client 中,登录/注册与完全相同的代码完美配合。
我检查了无数次凭据,令我困扰的是它在 expo 客户端中有效,但在独立应用程序中无效,所以我确信它与 google 配置有关,但我不知道是什么。
这是我的 app.json:
{
"expo": {
...
"scheme": "myapp",
"platforms": [
"ios",
"android"
],
...
"android": {
"package": "com.my_domain.myapp",
...
}
}
}
还有我的整合:
import React, { useState } from 'react';
import * as WebBrowser from "expo-web-browser";
import * as Google from 'expo-auth-session/providers/google';
import PillButton from '../UI/PillButton';
const SignupCmp = props => {
const [browserOpen, setBrowserOpen] = useState(null);
const [request, response, promptAsync] = Google.useAuthRequest({
expoClientId: '123-myuniqueid.apps.googleusercontent.com',
androidClientId: '123-myuniqueid.apps.googleusercontent.com'
});
useEffect(() => {
WebBrowser.warmUpAsync().then(r => console.log('warmed'));
return () => {
WebBrowser.coolDownAsync().then(r => console.log('cooled'));
};
}, []);
useEffect(() => {
if (response?.type === 'success') {
const { authentication } = response;
// console.log(authentication);
}
}, [response]);
const handleBrowserOpen = async (url) => {
let result = await WebBrowser.openBrowserAsync(url );
setBrowserOpen(result);
}
return (
<View>
<PillButton
disabled={!request}
title={I18n.t('authScreens.signupWithGoogle')}
type="solid"
onPress={() => { promptAsync().then(async val => {
props.googleAuth(val.authentication.accessToken);
}) }}
/>
</View>
);
};
export default SignupCmp;
我真的需要这方面的帮助,因为我没有想法。
更新
我更新了 useAuthRequest 中的 redirectUri 属性,如下所示:
const [request, response, promptAsync] = Google.useAuthRequest({
expoClientId: '123-myuniqueid.apps.googleusercontent.com',
androidClientId: '1234-myuniqueid.apps.googleusercontent.com',
redirectUri: AuthSession.makeRedirectUri({
native: 'myapp:/oauthredirect',
useProxy: true
}),
scopes: [
'profile',
'email'
]
}, {});
现在消息已更改为
Invalid parameter value for redirect_uri: Missing authority: myapp:/oauthredirect
expo 客户端中的登录仍然可以正常工作。
我尝试在 Google 控制台中创建一个新的 API 密钥,并在那里尝试了不同的设置,但似乎没有任何效果。
我真的可以得到一些帮助。 谢谢!
【问题讨论】:
标签: react-native expo google-signin