简体   繁体   中英

AWS Cognito Credentials Provider for IOS - access key and secret key are nil

I am trying to use AWSCognito in Objective C to authenticate to an Amazon SimpleDB database. I initalize an AWSCognitoCredentialsProvider with the identity pool id provided in my Amazon account. The problem is that when I try to get the access key and secret key from the AWSCognitoCredentialsProvider object, they are nil.

I initalize the credentials provider likes this:

 AWSCognitoCredentialsProvider *credentialsProvider = [AWSCognitoCredentialsProvider credentialsWithRegionType:AWSRegionUSEast1 accountId:ACCOUNT_ID identityPoolId:IDENTITY_POOL_ID unauthRoleArn:UNAUTH_ROLE authRoleArn:AUTH_ROLE];

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

[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

After that, I am trying to initialize a SimpleDB client likes this:

sdbClient = [[AmazonSimpleDBClient alloc] initWithAccessKey:[credentialsProvider accessKey] withSecretKey:[credentialsProvider secretKey]]; 

Am I doing something wrong?

Are you mixing version 1 and 2 of the AWS Mobile SDK for iOS? They are not designed to be used together, and you should consider migrating to the version 2 entirely.

The v2 SDK automatically calls - refresh on credentials providers when appropriate. Because you are not using AWSSimpleDB , - refresh has never been called, and that is why accessKey and secretKey return nil .

AWSCognitoCredentialsProvider generates AWS temporary credentials consisting of accessKey , secretKey , and sessionKey . - initWithAccessKey:withSecretKey: does not take temporary credentials, and even if you manually call - refresh on the credentials provider, AmazonSimpleDBClient does not function.

I recommend rewriting the app using AWSSimpleDB instead of AmazonSimpleDBClient in order to use Amazon Cognito Identity.

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