带有auth的aws-amplify是否损坏?

时间:2019-02-05 16:46:52

标签: javascript reactjs amazon-cognito aws-amplify

我正在尝试构建一个将使用aws托管ui进行身份验证的react应用。我正在尝试使用aws-amplify实现这一目标,到目前为止,我还没有运气。

Here文档指出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',
}

但是当我使用此配置设置时,出现以下错误。

  

参数:App客户端ID,App Web域,何时重定向URL   您已登录,退出时的重定向URL为   必填。

如您所见,这些参数已明确提供。因此,我单击了控制台中与错误消息链接的源映射文件,然后看到了。

if (data == null || !ClientId || !AppWebDomain || !RedirectUriSignIn || !RedirectUriSignOut) {
      throw new Error(this.getCognitoConstants().PARAMETERERROR);
    }

这使配置看起来更像这样。

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",
};

但是在执行此操作时,尝试将用户发送到文档说明为here的托管ui时,出现此错误。

  

未捕获的TypeError:无法读取未定义的属性“域”

我再次查看了源代码并找到了它。

var domain = config.domain,

这似乎使它期望配置不起作用。

在这一点上,我真的迷失了,根本无法使用任何帮助。

1 个答案:

答案 0 :(得分:3)

遍历Auth.ts代码,看来除了userPoolId之外,还必须包括userPoolWebClientIdoauth字段。这是我的工作方式:

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'
});