使用来自SAML身份验证和用户池的令牌响应来检索AWS临时访问密钥

时间:2018-06-29 16:11:27

标签: amazon-web-services aws-api-gateway amazon-cognito aws-amplify aws-userpools

如何使用SAML身份验证和用户池中的令牌响应来检索AWS临时访问密钥并进行API网关调用?

我已经为关联的App客户端配置了Cognito用户池。我已将Okta配置为第三方SAML身份提供商。使用Amazon托管登录名https://[cognito domain name]/login?response_type=token&client_id=[your App client id]&redirect_uri=[your App client redirect URL],我可以使用标头中的#access_token重定向到我的ReactJS应用程序。

我现在尝试使用#access_token来调用API网关。我一直在关注这个guide以及aws-amplify。据我了解,我需要使用#access_token获取AWS访问密钥来调用API网关。

我正在尝试使用以下代码进行操作:

AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:xxxxxxx-xxxx-xxxx-xxxx-xxxxxx',
   Logins: {
      'cognito-idp.us-east-1.amazonaws.com/us-east-1_xxxxxx': #access_token
   }
});

但不确定如何与aws-amplify集成,并且我还没有成功检索AWS临时访问密钥来进行API网关调用。

我以前使用Cognito用户池中的用户来进行此工作,但是现在我需要包括Okta作为身份提供者。

1 个答案:

答案 0 :(得分:1)

我发现需要#id_token而不是#access_token来完成我想做的事情。我通过在Cognito Pool App客户端设置中选择以下选项来启用#id_tokenenter image description here

然后我就可以关注Cognito hosted UI