node.js - 从 aws cli 或 nodeJS 创建 cognito 池 id 出错,参数有什么问题?

标签 node.js google-authentication amazon-cognito

我创建了nodeJS脚本来使用“CreateIdentityPool”类设置我的AWS Cognito池ID:

var cognitoidentity = new AWS.CognitoIdentity();
var params = {
    "IdentityPoolName": "samplePool",
    "AllowUnauthenticatedIdentities": true,
    "CognitoIdentityProviders": [
      {
        "ClientId": "xxxxxxxxxxx-qea4ebra0gipd0krefi37v8f48svrp8e.apps.googleusercontent.com", /* google client ID */
        "ProviderName": "accounts.google.com"
      }
    ],
    "DeveloperProviderName": "mypool"
};
cognitoidentity.createIdentityPool(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

但出现以下错误:

{ [ValidationException: 1 validation error detected: Value 'xxxxxxxxxxx-qea4ebra0gipd0krefi37v8f48svrp8e.apps.googleusercontent.com' at 'cognitoIdentityProviders.1.member.clientId' failed to satisfy constraint: Member must satisfy regular expression pattern: [\w_]+] message: '1 validation error detected: Value \'xxxxxxxxxxx-qea4ebra0gipd0krefi37v8f48svrp8e.apps.googleusercontent.com\' at \'cognitoIdentityProviders.1.member.clientId\' failed to satisfy constraint: Member must satisfy regular expression pattern: [\w_]+', code: 'ValidationException', time: Tue Jan 31 2017 21:11:48 GMT+1100 (AEDT), requestId: 'ad2b3366-e79d-11e6-b2e7-578f32ddcea5', statusCode: 400,
retryable: false, retryDelay: 45.71310137398541 }

第二种方式,我尝试首先在没有 CognitoIdentityProviders 的情况下创建身份池 ID,然后使用类“UpdateIdentityPool”运行更新以添加 CognitoIdentityProviders(解锁身份验证提供程序)。但是,上面是同样的问题。

第三种方法,我尝试使用来自aws cli的参数--cognito-identity-providers创建身份池ID,但仍然遇到同样的问题:

An error occurred (ValidationException) when calling the UpdateIdentityPool operation: 1 validation error detected: Value 'xxxxxxxxxxx-qea4ebra0gipd0krefi37v8f48svrp8e' at 'cognitoIdentityProviders.1.member.clientId' failed to satisfy constraint: Member must satisfy regular expression pattern: [\w_]+

第四种方法,我尝试从 aws cli 创建不带 --cognito-identity-providers 的身份池 ID,然后从 aws cli 更新它(添加 --cognito-identity-providers)。这仍然是同样的问题。

对这个问题非常沮丧,我必须从nodeJS 进行设置。因此,请不要提出从 AWS 控制台解锁身份验证提供商的建议。关于这个问题的引用文献非常少。如果您能将我链接到已解决的引用文献,我将不胜感激。

谢谢

最佳答案

您正在使用 CognitoIdentityProviders 但这适用于 AWS Cognito 用户池。您需要设置 SupportedLoginProviders 才能使其正常工作。像这样:

var params = {
    "IdentityPoolName": "samplePool",
    "AllowUnauthenticatedIdentities": true,
    "SupportedLoginProviders": {
        "accounts.google.com": "xxxxxxxxxxx-qea4ebra0gipd0krefi37v8f48svrp8e.apps.googleusercontent.com",
     }
};

关于node.js - 从 aws cli 或 nodeJS 创建 cognito 池 id 出错,参数有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41957451/

相关文章:

amazon-web-services - ALB 提示 cognito

javascript - 为什么我的 Async 和 Await 仍然没有完成序列执行的工作

node.js - 我应该将 yarn-error.log 添加到我的 .gitignore 文件吗?

node.js - Node webkit 和 Google OAuth

amazon-cognito - Cypress 与 amazon cognito 的集成测试

Angular + amazon-cognito-identity-js,为什么我收到错误 : global is not defined

node.js - Passport and JWT and Google Strategy - 谷歌回调后禁用 session 和 res.send()

node.js - 在 Node js 中运行 api 时引用错误。我已经创建了模型并且也需要它。但仍然无法正常工作

java - Android 上 Backendless google 轻松登录的 Redirect_url_mismatch 错误

c++ - 使用 openssl 和 c++ 生成 OAuth 访问 token