如何解决expo-auth-session / providers / google无法在独立应用程序上运行:invalid_scheme
我希望有人可以帮助我解决一段时间以来一直困扰着的以下问题。
我正试图在Expo SDK 39中的Android上使用expo-auth-session / providers / google进行Google Auth。
我遵循了指南here,但是我所做的一切最终都以一条Google消息结尾:
错误400:invalid_request redirect_uri的参数值无效: 无效的方案:com.my_domain.myapp:/ oauthredirect
我就是不明白我在做什么错。
我需要提到一个事实,在Expo Client中,登录/注册完全可以使用完全相同的代码来完成。
我无限次地检查了凭证,令我困扰的是它可以在expo客户端上运行,但不能在独立应用程序上运行,所以我确定它与google配置有关,但是我不知道什么。 / p>
这是我的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,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密钥,并在那里尝试了不同的设置,但似乎没有任何效果。
我真的可以提供一些帮助。 谢谢!
解决方法
我最终使用了import * as GoogleSignIn from 'expo-google-sign-in';
而不是import * as Google from 'expo-auth-session/providers/google';
看来这是使它正常工作的唯一方法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。