从 aws cli 或 nodeJS 创建认知池 ID 出错,参数有什么问题?

Create cognito pool id from aws cli or nodeJS got error, what's wrong with the params?

我创建了 nodeJS 脚本来设置我的 AWS Cognito 池 ID 使用 class "CreateIdentityPool":

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,然后使用 class "UpdateIdentityPool" 运行 更新以添加 CognitoIdentityProviders(解锁身份验证提供程序)。但是,上面是同样的问题。

第三种方式,我尝试使用参数 --cognito-identity-providersaws cli 创建身份池 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 控制台解锁身份验证提供程序的建议。这个问题的参考资料很差。如果你能 link 我解决参考问题,我将不胜感激。

谢谢

您正在使用 CognitoIdentityProviders 但那是针对 AWS Cognito 用户池的。您需要设置 SupportedLoginProviders 才能正常工作。像这样:

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