amazon-archives / aws-cognito-angular-quickstart

An Angular(v5)-based QuickStart single-page app utilizing Amazon Cognito, S3, and DynamoDB (Serverless architecture)
https://cognito.budilov.com
Apache License 2.0
689 stars 304 forks source link

Unable to get temporary credentials #132

Open shorabhd opened 6 years ago

shorabhd commented 6 years ago

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

mordka commented 6 years ago

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))