Cha*_*man 2 javascript reactjs amazon-cognito aws-amplify
我正在尝试构建一个 React 应用程序,它将使用 aws 托管的 ui 进行身份验证。我正在尝试使用 aws-amplify 来实现这一目标,但到目前为止我还没有这样的运气。
此处的文档说明 auth 配置应如下所示。
const oauth = {
domain : 'your-domain-prefix.auth.us-east-1.amazoncognito.com',
scope : ['phone', 'email', 'profile', 'openid','aws.cognito.signin.user.admin'],
redirectSignIn : 'http://www.example.com/signin/',
redirectSignOut : 'http://www.example.com/signout/',
responseType: 'code',
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用这个配置设置时,我收到以下错误。
参数:App客户端ID、App Web域、登录时的重定向URL和注销时的重定向URL。
如您所见,这些参数已明确提供。因此,我单击了带有错误消息的控制台中链接的源映射文件,并看到了这一点。
if (data == null || !ClientId || !AppWebDomain || !RedirectUriSignIn || !RedirectUriSignOut) {
throw new Error(this.getCognitoConstants().PARAMETERERROR);
}
Run Code Online (Sandbox Code Playgroud)
这使得它看起来更像是配置应该看起来像这样。
const auth = {
AppWebDomain: "aaaaa",
TokenScopesArray: ["phone", "email", "profile", "openid", "aws.cognito.signin.user.admin"],
RedirectUriSignIn: "http://localhost:3000",
RedirectUriSignOut: "http://localhost:3000",
responseType: "token",
ClientId: "aaa",
UserPoolId: "aaa",
};
Run Code Online (Sandbox Code Playgroud)
但是在执行此操作并尝试将用户发送到托管的 ui 时,如文档所述,我收到此错误。
未捕获的类型错误:无法读取未定义的属性“域”
我再次查看来源并找到了这个。
var domain = config.domain,
Run Code Online (Sandbox Code Playgroud)
这使它看起来像是在期待不起作用的配置。
在这一点上,我真的很迷茫,可以使用任何帮助。
小智 6
通过走出去Auth.ts的代码,看来,你必须包括userPoolId和userPoolWebClientId领域,除了oauth。这是我如何让它工作的:
const oauth = {
domain: 'XXXXXX.auth.us-west-2.amazoncognito.com',
scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
redirectSignIn: 'http://localhost:3000/',
redirectSignOut: 'http://localhost:3000/',
responseType: 'code'
};
Auth.configure({
oauth: oauth,
region: 'us-west-2',
userPoolId: 'us-west-2_XXXXXXXXX',
userPoolWebClientId: 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4209 次 |
| 最近记录: |