reactjs - AWS Amplify Google 身份验证用户未重定向回
问题描述
我正在尝试使用 AWS Amplify 在 React 本机应用程序中实现 Google 身份验证。我已经在我的应用程序中安装了 Amplify 并且还安装了 Auth。
授权的javascript来源:
https://inventory053721f5-053721f5-develop.auth.eu-west-1.amazoncognito.com
授权重定向 uri:
https://inventory053721f5-053721f5-develop.auth.eu-west-1.amazoncognito.com/oauth2/idpresponse
aws-exports.js:
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = {
"aws_project_region": "eu-west-1",
"aws_cognito_identity_pool_id": "***",
"aws_cognito_region": "eu-west-1",
"aws_user_pools_id": "***",
"aws_user_pools_web_client_id": "***",
"oauth": {
"domain": "***",
"scope": [
"phone",
"email",
"openid",
"profile",
"aws.cognito.signin.user.admin"
],
"redirectSignIn": "inventory://",
"redirectSignOut": "inventory://",
"responseType": "code"
},
"federationTarget": "COGNITO_USER_POOLS"
};
export default awsmobile;
我的App.tsx
样子是这样的:
import React, {FunctionComponent} from 'react';
import Amplify, {Auth} from 'aws-amplify';
import {Button} from 'react-native';
import config from '../../aws-exports';
Amplify.configure(config);
export interface AppProps {}
const App: FunctionComponent<AppProps> = () => {
return <Button title={'Login'} onPress={() => Auth.federatedSignIn()} />;
};
export default App;
发生了什么的视频:
解决方案
在设置 Amplify Auth 并配置您的社交提供者之后,您还必须设置链接,以便您的应用可以处理从 Web 浏览器返回到您的应用的回调:
- 请注意您在运行时为“重定向登录 uri”输入的值
amplify add auth
(例如myapp:\\
)。 - 对于在 iOS 上使用 react-native-cli(而不是 Expo)制作的应用程序,请打开 Xcode 项目(在 ios 文件夹中,rnamplify.xcworkspace)。然后
info.plist
作为源代码打开并添加以下内容:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp</string>
</array>
<dict>
</array>
- 对于在 Android 上使用 react-native-cli(而不是 Expo)制作的应用程序,在 Android Studio 中打开 android/app/main/AndroidManifest.xml 并添加以下内容
intent-filter
:
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
</intent-filter>
如果您的应用程序是使用 Expo 制作的,而不是使用 react-native-cli,那么您将不会执行上面的步骤 2 和 3。而是打开您的app.json
文件并将scheme
键值对添加到“expo”属性:
{
"expo": {
"scheme": "myapp"
}
}
推荐阅读
- javascript - 如何在 react-admin 中访问自定义组件中的表单数据?
- php - 如何使用php检查给定的日期时间是否早于当前日期时间
- javascript - 如何使用 JavaScript 获取网页列 innerText?
- mongodb - 有什么方法可以更新mongodb中的数据
- java - 如何在 Java 代码中实现 Scala Trait
- segmentation-fault - 分段错误 - fortran 中的无效内存引用问题
- ruby-on-rails - 当其中有数据时,为什么这个数组元素会返回 nil?
- python - 如何获得使用什么类型的激活?
- vb.net - 使用 Visual Studio 在本地驱动器 C 中以 .txt 格式导出文本
- git - Git 合并仅在分支内提交