Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Cognito IdentityId?

I am trying to get AWS credentials for a user I have just created.

Can anyone tell me what identityId is supposed to be? I have tried concatenating the region with the user sub but it isn't having it:

var params = {
  UserPoolId: process.env.USER_POOL_ID,
  Username: '[email protected]',
  TemporaryPassword: 'Passw0rd!'
};

var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
cognitoidentityserviceprovider.adminCreateUser(params, function(err, data) {
  if (err) {
    callback(null, failure(err));  
  }else    
    var identityId =  "us-east-1:" + data.User.Username  //user sub

    var cognitoidentity = new AWS.CognitoIdentity();
    cognitoidentity.getCredentialsForIdentity(
      {"IdentityId": identityId},
      (err, credResult) => {
        if(err){
          callback(null, failure(err));
        }
        callback(null, success(credResult));
    })
});

I just get :

{
  "message":"Identity 'us-east-1:8ce7ee63-d9ae-4f12-9xxxxxx' not found.", 
  "code":"ResourceNotFoundException","t": "..."
}
like image 332
1977 Avatar asked Jan 26 '18 14:01

1977


People also ask

What is identityId?

To summarize: IdentityId is the Id of your user in the Identity pool from Cognito Federated Identities.

What is Cognito use for?

Developers can use Cognito Identity to add sign-up and sign-in to their apps and to enable their users to securely access their app's resources. Cognito also enables developers to sync data across devices, platforms, and applications.

What is the use of Cognito user pool?

A user pool is a user directory in Amazon Cognito. With a user pool, your users can sign in to your web or mobile app through Amazon Cognito. Your users can also sign in through social identity providers like Google, Facebook, Amazon, or Apple, and through SAML identity providers.

Where do I find my Cognito identity ID?

Retrieving an Amazon Cognito identity If an identity ID is already set on your provider, you can call credentialsProvider. identityId to retrieve that identity, which is cached locally. However, if an identity ID is not set on your provider, calling credentialsProvider. identityId will return nil .


1 Answers

You seem to be mixin Cognito User Pools with Cognito Federated Identities. Cognito User Pool is where you manage your users, and Federated Identities is where you give access to external users AWS credentials.

Said that, you have to make sure you have your Identity Pool (from Federated Identities) configured to give access to the users from your User Pool. This might help you with that https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html

After setting that up you may call CognitoIdentity.getId that will give your IdentityId only after that you can get the credentials.

To summarize: IdentityId is the Id of your user in the Identity pool from Cognito Federated Identities.

like image 141
dege Avatar answered Oct 22 '22 09:10

dege