【发布时间】:2020-09-08 08:28:51
【问题描述】:
我在实施 Expo Auth Session 时遇到问题。
我正在 Expo Auth Session 中尝试使用 Google Oauth 登录,如下所述:https://docs.expo.io/guides/authentication/#google
WebBrowser.maybeCompleteAuthSession();
const GoogleButton = () => {
// Endpoint
const discovery = useAutoDiscovery('https://accounts.google.com');
// Request
const [request, response, promptAsync] = useAuthRequest(
{
clientId: 'MYID',
scopes: ['email', 'profile'],
// For usage in managed apps using the proxy
redirectUri: makeRedirectUri({
// For usage in bare and standalone
native: 'com.googleusercontent.apps.MYID://redirect',
useProxy: true,
}),
},
discovery,
);
console.log(request);
console.log(response);
return (
<Button
onPress={promptAsync}
icon={GoogleIcon}
/>
);
};
浏览器打开,我可以用谷歌成功登录,但是当我被重定向到应用程序时,响应解析为Object { "type": "dismiss", }
我还尝试使用不同的 oauth 服务来实现 oauth:
WebBrowser.maybeCompleteAuthSession();
const HiveButton = () => {
// Endpoint
const discovery = {
authorizationEndpoint:
'https://hivesigner.com/login-request/my.app',
};
// Request
const [request, response, promptAsync] = useAuthRequest(
{
scopes: ['posting'],
// For usage in managed apps using the proxy
redirectUri: makeRedirectUri({
useProxy: true,
}),
},
discovery,
);
console.log(request);
console.log(response);
return (
<Button
onPress={promptAsync}
icon={HiveIcon}
/>
);
};
浏览器打开,我可以成功登录,但我没有被重定向到应用程序,而是收到“尝试完成登录时出错。请关闭此屏幕以返回应用程序。”在 auth.expo.io/@me/myapp 上,即使参数代码具有我想要传递给我的应用程序的正确登录令牌。
【问题讨论】:
标签: react-native oauth expo