AWS Cognito-如何刷新Angular中的令牌?

时间:2018-11-05 09:54:34

标签: angular amazon-web-services token amazon-cognito

我尝试了此代码,

    const cognitoisp = new AWS.CognitoIdentityServiceProvider();

    const params = {
      AuthFlow: 'REFRESH_TOKEN',
      ClientId: '',
      UserPoolId: '',
      AuthParameters: {
        'REFRESH_TOKEN': ''
      }
    };

    cognitoisp.adminInitiateAuth(params, function (err, data) {
      if (err) {
        console.log('RefreshTokenError: ', err.stack);
      } else {
        console.log('RefreshTokenResponse: ', data);
      }
    });

,但不起作用。还是还有其他刷新令牌的方法?

1 个答案:

答案 0 :(得分:0)

adminInitiateAuth函数仅供管理Cognito的人员使用,您需要使用initateAuth

const params = {
  AuthFlow: 'REFRESH_TOKEN_AUTH',
  ClientId: 'YOUR_CLIENT_ID!',
  AuthParameters: {
    'REFRESH_TOKEN': 'THE_REFRESH_TOKEN!'
  }
};

cognitoisp.initiateAuth(params, function (err, data) {
  if (err) {
    console.log('RefreshTokenError: ', err.stack);
  } else {
    console.log('RefreshTokenResponse: ', data);
  }
});