如何将 Cognito 令牌传递到 Amazon API Gateway? [英] How to pass Cognito token to Amazon API Gateway?

查看:29
本文介绍了如何将 Cognito 令牌传递到 Amazon API Gateway?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于 Amazon API Gateway 的网络应用程序.现在我创建了 Facebook 登录并成功登录到网站.但是当我调用另一个 API 时,一切都消失了.我认为每次调用 API 时我都应该传递 Cognito 令牌.我说得对吗?

I'm developing web app based on Amazon API Gateway. Now I created Facebook login and successfully logged into website. but when I call another API, everything gone. I think I should pass Cognito token when call API everytime. am I right?

如果是,如何将 Cognito 令牌传递给 API?喜欢标题?或者其他方式?

if yes, how to pass Cognito token to API? like header? or another way?

谢谢,

推荐答案

您正在使用来自 cognito 身份的Basic Authflow",这意味着您需要通过调用 STS 的AssumeRoleWithWebIdentity"来为您的用户获取凭据.以下是一些帮助文档:http://docs.aws.amazon.com/cognito/devguide/identity/concepts/authentication-flow/

You are using the "Basic Authflow" from cognito identity, which means you will need to get credentials for your users by calling STS's "AssumeRoleWithWebIdentity". Here is some documentation to help: http://docs.aws.amazon.com/cognito/devguide/identity/concepts/authentication-flow/

拥有凭据后,您可以实例化 API 网关客户端:

Once you have credentials, you can instantiate the API Gateway Client:

var client = apigClientFactory.newClient({ 
    accessKey: ACCESS_KEY, 
    secretKey: SECRET_KEY, 
    sessionToken: SESSION_TOKEN });

密钥和令牌来自AssumeRoleWithWebIdentity"调用的结果.

The keys and tokens come from the result of the "AssumeRoleWithWebIdentity" call.

如果您已正确配置 IAM 角色和授权,您应该能够访问您的 API.

If you have configured your IAM roles, and Authorizations correctly you should be able to access your API.

这是描述如何配置角色的文档 &授权:http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings.html#how-to-method-settings-callers-console

Here is the documentation describing how to configure the roles & authorization: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings.html#how-to-method-settings-callers-console

此外,这里是如何启用 CORS - http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html

Also, here is how to enable CORS - http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html

这篇关于如何将 Cognito 令牌传递到 Amazon API Gateway?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆