Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

Is there any way I can make the handshake via Lambda functions?

like image 969
JordanBelf Avatar asked Dec 22 '16 01:12

JordanBelf


1 Answers

I think Lambda along with API Gateway offer a good solution. API Gateway allows you to create a persistent, publicly accessible HTTP endpoint. You can define specific 'resources' that map HTTP methods to lambda function calls.

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.

Register the API Gateway endpoint as your application's callback URI, which would look something like this:

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.

like image 190
rumdrums Avatar answered Sep 23 '22 05:09

rumdrums