Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix websocket authorizers data located in wrong place #1360

Merged
merged 3 commits into from
May 11, 2022

Conversation

DocLM
Copy link
Contributor

@DocLM DocLM commented Mar 31, 2022

Move authorizer and identity data to requestContext in order to follow lambda proxy specs.

Description

This pull request fix a wrong identity and authorizer informations contained in the lambda event instead of requestContext object

Relates to #1379

Motivation and Context

This fix a wrong behaviour for lambda and websocket authorizers.
Authorizer and identity data should be inside requestContext object when used with lambda proxy (like serverless-offline does)

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html

In particular a reference to:

For the Lambda proxy integration, API Gateway passes the context object from a Lambda authorizer directly to the backend Lambda function as part of the input event. You can retrieve the context key-value pairs in the Lambda function by calling $event.requestContext.authorizer.key.

Also integrated changes from #1376 in order to adhere to AWS behaviour: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html

You can access the stringKey, numberKey, or booleanKey value (for example, "value", "1", or "true") of the context map in a mapping template by calling $context.authorizer.stringKey, $context.authorizer.numberKey, or $context.authorizer.booleanKey, respectively. The returned values are all stringified. Notice that you cannot set a JSON object or array as a valid value of any key in the context map. 

How Has This Been Tested?

Detected the difference between AWS and serverless-offline
Reflect the changes in current websocket tests in order to catch the behaviour change

Screenshots (if appropriate):

@DocLM DocLM force-pushed the bugfix/websocket-authorizers branch from c9d512e to 7f9d6c4 Compare April 10, 2022 07:04
@DocLM DocLM changed the title Fix websocket authorizers data according to specs Fix websocket authorizers data located in wrong place Apr 10, 2022
@DocLM DocLM force-pushed the bugfix/websocket-authorizers branch 2 times, most recently from d2c106c to c74d3c3 Compare April 14, 2022 06:31
@DocLM DocLM force-pushed the bugfix/websocket-authorizers branch from c74d3c3 to 53e4f9c Compare April 20, 2022 19:24
@DocLM DocLM mentioned this pull request Apr 20, 2022
@DocLM DocLM force-pushed the bugfix/websocket-authorizers branch from 53e4f9c to cdec9ff Compare April 20, 2022 19:36
@dnalborczyk
Copy link
Collaborator

thank you @DocLM !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants