AWS Cognito iOS开发人员身份validation身份

我正在尝试使用开发人员身份validation的亚马逊认知。 我的API成功返回一个id和令牌。 但是,当我使用这些令牌上传内容到S3我收到以下错误:

Not authorized to perform sts:AssumeRoleWithWebIdentity 

以下是我设置凭证提供程序的代码。

 ZGAWSIdentityProvider *identityProvider = [ZGAWSIdentityProvider new]; [identityProvider setIdentityPoolId:AWS_IDENTITY_POOL_ID]; AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityProvider:identityProvider unauthRoleArn:AWS_UNAUTH_ROLE_ARN authRoleArn:AWS_AUTH_ROLE_ARN]; AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSWest1 credentialsProvider:credentialsProvider]; [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration; 

我正在使用http://docs.aws.amazon.com/mobile/sdkforios/developerguide/cognito-auth.html#create-an-identity-pool-that-supports-developer-authenticatedidentities提供的模板创build身份提供者。

 @implementation ZGAWSIdentityProvider @synthesize identityPoolId=_identityPoolId; @synthesize identityId=_identityId; @synthesize token=_token; - (BFTask *)getIdentityId { // Should ensure that identityId property is valid. The below code can probably // be used for most use cases. if (self.identityId) { return [BFTask taskWithResult:nil]; } else { return [[BFTask taskWithResult:nil] continueWithBlock:^id(BFTask *task) { if (!self.identityId) { return [self refresh]; } return nil; }]; } } - (BFTask *)refresh { BFTaskCompletionSource *task = [BFTaskCompletionSource taskCompletionSource]; __weak __typeof(self)weakSelf = self; [[ZGAccountController sharedInstance] getAWSCredentialsWithCompletion:^(NSDictionary *credentials) { if (credentials && [credentials objectForKey:@"identity_id"] && [credentials objectForKey:@"identity_id"]) { __strong __typeof(weakSelf)strongSelf = weakSelf; strongSelf.identityId = [credentials objectForKey:@"identity_id"]; strongSelf.token = [credentials objectForKey:@"token"]; [task setResult:nil]; } else { NSError *error = [NSError errorWithDomain:@"com.##.##" code:-1 userInfo:nil]; [task setError:error]; } }]; return task.task; } @end 

这似乎是angular色信任的问题。 我使用亚马逊网页界面创build了身份池,并且双重检查身份池ID是否正确。 我已经能够成功上传w未经身份validation的身份,所以我相信是不是一个angular色的权限问题。

对不起,所有的烦恼。

身份提供者和凭证提供者之间的交互方式存在一个小问题,那就是没有正确logging或处理好。 凭据提供程序根据是否在提供程序上附加login名,使用unauth或authangular色arn进行转向。 如果您没有在提供程序上存储任何其他login名,则会将其视为未经身份validation,并使用unauthangular色并导致出现STS错误。 您可以通过在身份提供程序的刷新中执行以下操作来解决此问题:

 // add login to the map to make sure CredentialsProvider treats us as authenticated NSMutableDictionary *temp = [NSMutableDictionary dictionaryWithDictionary:self.logins]; [temp setObject:@"temp" forKey:@"myprovider"]; self.logins = temp; 

更新2015-03-10 :您可能需要考虑查看我们的端到端示例,以获得更好的处理方法。

这个示例中,我们包含用户标识符的实际值,然后将logins属性的全部内容传递给后端。

如果您在未经authentication的情况下成功完成此操作,则可能会出现一些可能性。

首先,确保你未经身份validation的angular色arn不同于你的身份validationangular色arn。 此外,请确保在信任策略(可通过此链接中的适当angular色访问)中,amr指向“已authentication”。

如果您有任何其他问题, 这篇博客文章将在高层次进行。