【问题标题】:AWS Cognito Identity NullAWS Cognito 身份空
【发布时间】:2014-10-04 09:31:51
【问题描述】:

我正在使用 AWS Cognito 进行用户身份验证,我正在尝试测试未经身份验证的用户,但我从 Cognito 得到的只是一个空身份。下面的代码是关于 viewDidLoad 方法的:

AWSCognitoCredentialsProvider *credentialsProvider = [AWSCognitoCredentialsProvider
                       credentialsWithRegionType:AWSRegionUSEast1
                       accountId:@"XXXXXXXXXXXX"
                       identityPoolId:@"us-east-1:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
                       unauthRoleArn:@"arn:aws:iam::XXXXXXXXXXXX:role/Cognito_XXXXXXXXXUnauth_DefaultRole"
                       authRoleArn:@"arn:aws:iam::XXXXXXXXXXXX:role/Cognito_XXXXXXXXXAuth_DefaultRole"];

AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1
                                                                      credentialsProvider:credentialsProvider];

[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

[[credentialsProvider getIdentityId] continueWithSuccessBlock:^id(BFTask *task){
    NSString* cognitoId = credentialsProvider.identityId;
    NSLog(@"cognitoId: %@", cognitoId);
    //[self launchCount];
    return nil;
}];

所以从上面的 NSLog 我得到:

cognitoId: (null)

以下是授权和未授权用户的认知认证策略:

{
  "Version": "2012-10-17",
  "Statement":[{
  "Effect":"Allow",
  "Action":"cognito-sync:*",
  "Resource":["arn:aws:cognito-sync:us-east-1:XXXXXXXXXXXX:identitypool/${cognito- identity.amazonaws.com:aud}/identity/${cognito-identity.amazonaws.com:sub}/*"]
  }]
}

任何想法可能是什么,或者我做错了什么?

【问题讨论】:

  • 您好,我已经进行了这种身份验证,问题是您是否为认知配置了身份池和角色?
  • 是的,我配置了它们,上面的配置是针对授权和未授权的角色。
  • 显示下面代码块的错误。

标签: ios amazon-web-services amazon-cognito


【解决方案1】:

请运行此代码并告知错误。

[[credentialsProvider getIdentityId] continueWithBlock:^id(BFTask *task){

if (task.error == nil)
{
   NSString* cognitoId = credentialsProvider.identityId;
   NSLog(@"cognitoId: %@", cognitoId);               
}
else
{
    NSLog(@"Error : %@", task.error);
}

return nil;
}];

【讨论】:

  • 它确实有效,cognito 回复了我以下内容: cognitoId: us-east-1:a84b2f24-2759-48ce-aee1-80dcbb694919 那么,你能解释一下发生了什么吗?
  • 你的问题解决了。你连接正确。如果是,请检查正确的答案。
猜你喜欢
  • 2016-10-02
  • 2018-01-29
  • 1970-01-01
  • 2016-06-25
  • 1970-01-01
  • 2017-01-02
  • 2018-05-22
  • 2016-08-27
  • 2018-08-31
相关资源
最近更新 更多