简体   繁体   中英

AWS Cognito Identity Null

I'm using AWS Cognito for user authentication, I'm trying to test unauthenticated users but all I get from Cognito is a null identity. The code below is on a viewDidLoad method:

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;
}];

So from the NSLog above I'm getting:

cognitoId: (null)

Below is the cognito authentication policy for authorized and unauthorized users:

{
  "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}/*"]
  }]
}

Any ideas what could it be, or what am I doing wrong?

Please run this code and tell error.

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

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

return nil;
}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM