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

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

问题描述

我正在基于Amazon API Gateway开发Web应用程序。现在,我创建了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?

谢谢

推荐答案

您正在使用认知身份的基本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天全站免登陆