Amplify-js: Using Auth to retrieve accessKeyId, secretAccessKey and sessionToken equivilent directly from Amplify

Created on 7 Sep 2019  路  1Comment  路  Source: aws-amplify/amplify-js

* Which Category is your question related to? *
Authorisation - AWS Cognito via Amplify
* What AWS Services are you utilizing? *
AWS Amplify, Auth, Cognito
* Provide additional details e.g. code snippets *
I would like to know what the equivalent function is in Amplify using Auth in order to retrieve the following values:

// Make the call to obtain credentials
AWS.config.credentials.get(function(){

    // Credentials will be available when this function is called.
    var accessKeyId = AWS.config.credentials.accessKeyId;
    var secretAccessKey = AWS.config.credentials.secretAccessKey;
    var sessionToken = AWS.config.credentials.sessionToken;

});

I have looked at the results of Auth.currentSession and Auth.currentAuthenticatedUser and can see the following:

idToken.jwtToken
accessToken.jwtToken
refreshToken.token

Are these the correct values? Reason for asking is that I need to run SigV4Utils against one of my URLs using those values to create a signed URL.

Any help much appreciated!

Auth pending-close-response-required question

Most helpful comment

Hi @kirkryan thanks for your question.

For AWS credentials you can get it by using Auth.currentCredentials() like this

Auth.currentCredentials()
  .then(credentials => {
    const awsCreds = Auth.essentialCredentials(credentials);
    //...
  });

>All comments

Hi @kirkryan thanks for your question.

For AWS credentials you can get it by using Auth.currentCredentials() like this

Auth.currentCredentials()
  .then(credentials => {
    const awsCreds = Auth.essentialCredentials(credentials);
    //...
  });
Was this page helpful?
0 / 5 - 0 ratings