我正在尝试将 amazon cognito 与开发人员身份验证一起使用。我的 API 成功返回了一个 id 和 token。但是,当我使用这些令牌将内容上传到 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-authenticated-identities提供的模板创建身份提供者。
@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
这似乎是角色信任的问题。我使用亚马逊网络界面创建了身份池,并仔细检查了身份池 ID 是否正确。我已经能够成功上传 w 未经身份验证的身份,所以我相信不是角色权限问题。