Skip to content

Can you pass the entire authentication context for an HTTP URI integration in API Gateway HTTP or REST?

0

I'm using Amazon API Gateway (either REST or HTTP API) with an authorizer, and I access my backend through a PrivateLink. I want to retrieve information about the Cognito user accessing the API and securely pass it to the backend. However, when I use either a Lambda Authorizer or direct integration with Cognito, the user information doesn’t reach the backend. How can I configure API Gateway to ensure that Cognito user data (e.g., username, email) is passed as payload to my backend after authorization?

1 Answer
0

If you're using a Lambda authorizer, you can choose what information to pass to the back end using the context key. That way you can be very specific about the information taken from the inbound call and supply that to the back end.

In your code, where you would normally do something like return {'isAuthorized':True} you could instead do return {'isAuthorized':True, 'context':{'cognitoUsername':'yourDataHere', 'email':'emailDataHere'}}

Ref: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html

EXPERT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.