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": "..."
}
To summarize: IdentityId is the Id of your user in the Identity pool from Cognito Federated Identities.
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.
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With