Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Cognito connection cannot find IdentityPool

I've spent a day trying to get Cognito working on my server. I find none of the documentation of much help as there are no clear examples of setting it all up.

I have the following code on my server:

BasicAWSCredentials credentials = new BasicAWSCredentials(
        "A**************",
        "+y*****************************");

AmazonCognitoIdentityClient client =
        new AmazonCognitoIdentityClient(credentials);
GetOpenIdTokenForDeveloperIdentityRequest tokenRequest =
        new GetOpenIdTokenForDeveloperIdentityRequest();
tokenRequest.setIdentityPoolId("eu-west-1:be9d19a5-*******************");
HashMap<String, String> map = new HashMap<String, String>();

//Key -> Developer Provider Name used when creating the identity pool
//Value -> Unique identifier of the user in your <u>backend</u>
map.put("access.com.cbn.postref", "fred");

//Duration of the generated OpenID Connect Token
tokenRequest.setLogins(map);
tokenRequest.setTokenDuration(1000l);

GetOpenIdTokenForDeveloperIdentityResult result = client
        .getOpenIdTokenForDeveloperIdentity(tokenRequest);
String identityId = result.getIdentityId();
String token = result.getToken();

System.out.println("id = " + identityId + "  token = " + token);

I have created an IAM user and used the public and private keys in the code above. I've created an IndentityPool on Cognito with the Dev. Auth. Id as given in the code: access.com.cbn.postref.

When I run this code I get an exception thus:

com.amazonaws.services.cognitoidentity.model.ResourceNotFoundException: IdentityPool 'eu-west-1:be9d19a5-***********************' not found. (Service: AmazonCognitoIdentity; Status Code: 400

Generated at

GetOpenIdTokenForDeveloperIdentityResult result = client
                .getOpenIdTokenForDeveloperIdentity(tokenRequest);

I'm at a complete loss as to know how to proceed as I cannot see what I've done wrong. I did try getting the list of IdentityPools but that returns a list of 0 size.

like image 358
cbn Avatar asked Nov 25 '14 21:11

cbn


1 Answers

When accessing an identity pool in the eu-west-1 region, you must explicitly set the region of your client to use that region:

client.setRegion(Region.getRegion(Regions.EU_WEST_1)); 

We are currently working on an example developer authenticated identities backend plus iOS/Android application we hope to release soon.

like image 159
Bob Kinney Avatar answered Sep 27 '22 15:09

Bob Kinney