简体   繁体   English

是否可以使用AWS Lambda来请求oauth 2.0令牌?

[英]Is it possible to use AWS Lambda to request an oauth 2.0 token?

I am looking for ways to avoid creating an ec2 instance in order to have a valid callback URL to perform the oauth handshake. 我正在寻找避免创建ec2 instance ,以便拥有一个有效的回调URL来执行oauth握手。

I plan to use Lambda to connect to a remote API , but I need to be able to get the token first, which is valid only for 6 hours. 我计划使用Lambda连接到远程API ,但我需要能够首先获取令牌,该令牌仅在6小时内有效。

Is there any way I can make the handshake via Lambda functions? 有什么方法可以通过Lambda函数进行握手吗?

I think Lambda along with API Gateway offer a good solution. 我认为LambdaAPI Gateway提供了一个很好的解决方案。 API Gateway allows you to create a persistent, publicly accessible HTTP endpoint. API Gateway允许您创建持久的,可公开访问的HTTP端点。 You can define specific 'resources' that map HTTP methods to lambda function calls. 您可以定义将HTTP方法映射到lambda函数调用的特定“资源”。

I'm not especially familiar with OAuth 2, but I'm imagining something like this: In API Gateway, define a resource '/callback' with a GET method that invokes your Lambda function. 我对OAuth 2并不是特别熟悉,但我想象的是:在API网关中,使用调用Lambda函数的GET方法定义资源'/ callback'。

Register the API Gateway endpoint as your application's callback URI, which would look something like this: 将API Gateway端点注册为应用程序的回调URI,如下所示:

https://c1bql2cdxy.execute-api.us-east-1.amazonaws.com/callback https://c1bql2cdxy.execute-api.us-east-1.amazonaws.com/callback

By doing so, the remote service will invoke your lambda function, which can then read the authorization token from the request and use it however needed, whether that involves 1) storing the token in a database for future use (and reuse) by other services, 2) directly invoking the services within the same Lambda function, etc. 通过这样做,远程服务将调用您的lambda函数,然后该函数可以从请求中读取授权令牌并根据需要使用它,无论是否涉及1)将令牌存储在数据库中以供将来使用(和重用)其他服务,2)直接调用同一Lambda函数中的服务等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM