aws-cognito-angular-quickstart icon indicating copy to clipboard operation
aws-cognito-angular-quickstart copied to clipboard

Unable to get temporary credentials

Open shorabhd opened this issue 7 years ago • 1 comments

Hi,

I implemented your code in my angular project. I am able to fetch tokenID from AWS Cognito after verification but when I see credentials, it shows

accessKeyId:undefined data:null expireTime:null expired:true

I implemented, login, signup from your project. After successful login I am directly redirecting it to JWT. It displays the tokens. But When I tried printing the CognitoIdentityCredentials object it shows nothing.

I have done this in JWT callbackWithParam function:

AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: environment.identityPoolId, Logins: { 'cognito-idp.{{region}}.amazonaws.com/{{userpoolid}}' : idToken } });

Any idea what I might be doing wrong?

Regards, Shorabh

shorabhd avatar Mar 20 '18 18:03 shorabhd

AWS.config.credentials is a magic wrapper over credentials, and its asynchronous operation to get temporary keys. Try .get() or .refresh() methods on credentials object. You can create promise:

     AWS.config.credentials.get((err) => {
        if (err) {
          rejection(err)
        } else {
          resolve(AWS.config.credentials)
        }
      })
    })

and then use it getCredentials.then(creds=> doSomething(creds))

mordka avatar Mar 29 '18 14:03 mordka