0

我最近开始使用 AWS 开发工具包以及用户如何在身份池中使用 Cognito 进行身份验证。查询凭据时,我有以下问题:以下方法在多大程度上不同?

  1. 方法:getId() 和 getCredentialsForIdentity():
const cognitoidentity = new AWS.CognitoIdentity()
    var params = {
      IdentityPoolId: 'STRING_VALUE', /* required */
      AccountId: 'STRING_VALUE',
      Logins: {
        '<IdentityProviderName>': 'STRING_VALUE',
        /* '<IdentityProviderName>': ... */
      }
    };
    cognitoidentity.getId(params, function(err, data) {
      if (err) console.log(err, err.stack); // an error occurred
      else     console.log(data);           // successful response
    });


    var params = {
      IdentityId: 'STRING_VALUE', /* required */
      CustomRoleArn: 'STRING_VALUE',
      Logins: {
        '<IdentityProviderName>': 'STRING_VALUE',
        /* '<IdentityProviderName>': ... */
      }
    };
    cognitoidentity.getCredentialsForIdentity(params, function(err, data) {
      if (err) console.log(err, err.stack); // an error occurred
      else     console.log(data);          // data AccesKeyId,Expiration, SecretKey, SessionToken
    });
  1. 方法:
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
        IdentityPoolId: identityPoolId,
        Logins:{
                'Provider': jwtToken    
            },
        region: "eu-central-1"
      });

 AWS.config.credentials.get(function(){
    
        // Credentials will be available when this function is called.
        const{ accessKeyId} = AWS.config.credentials
        const {secretAccessKey} = AWS.config.credentials
        const {sessionToken} = AWS.config.credentials
        
        
      })

两次尝试的凭据不同,SessionToken 相同。第一次尝试获得的 SecretKey 和第二次尝试获得的 SecretAccesKey 有什么区别?

这两种尝试有什么区别?

第一次尝试:使用 GetId 和 GetCredentialsForIdentity 增强简化的 authflow https://docs.aws.amazon.com/cognito/latest/developerguide/authentication-flow.html

第二次尝试: https ://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-browser-credentials-cognito.html

我很感激任何帮助:)

4

1 回答 1

0

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityCredentials.html

据此,它在后台做同样的事情。SecretKey 和 SecretAccesKey 的语法差异似乎纯粹是装饰性的。我在boto3中注意到了同样的情况。无论如何,您都可以使用 accesskey 和 sessionid 来验证其他 AWS 服务。

于 2022-01-21T06:58:06.963 回答