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

feat: Support websockets authorizers #1350

Merged
merged 5 commits into from
Mar 15, 2022

Conversation

DocLM
Copy link
Contributor

@DocLM DocLM commented Mar 13, 2022

Description

Extend current API Gateway implementation to support Authorizers with Websockets.

More information on AWS official docs: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-lambda-auth.html

Related:

Motivation and Context

This change is required since serverless-offline currently support authorizers only in HTTP routes.
This functionality now allow to test websocket authorizers without using real infrastructure.

How Has This Been Tested?

This change is tested using integration tests in tests/integration/websocket-authorizer.
Tested functionalities includes:

  • Authorizer succedeed with a allow policy;
  • Authorizer succedeed with a deny policy;
  • Authorizer returns Unauthorized response;
  • Authorizer terminate with an error.

Also manually tested against real authorizers used in real applications

@DocLM DocLM changed the title Feature/websocket authorizers feature: websocket authorizers Mar 13, 2022
@DocLM DocLM force-pushed the feature/websocket-authorizers branch 2 times, most recently from d063557 to e20ae2f Compare March 14, 2022 18:23
@DocLM
Copy link
Contributor Author

DocLM commented Mar 14, 2022

Hi @pgrzesik, now should pass tests on NodeJS 12

@DocLM DocLM force-pushed the feature/websocket-authorizers branch from e20ae2f to 3bb0d00 Compare March 14, 2022 20:52
Copy link
Collaborator

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one minor question, overall the implementation looks good 👍 Thanks @DocLM

endpoint.authorizer.type &&
endpoint.authorizer.type.toUpperCase() === 'TOKEN'
) {
if (this.log) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should just log here instead of erroring out? What's the reasoning behind it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pgrzesik can you please help review this PR: #1348

Copy link
Contributor Author

@DocLM DocLM Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pgrzesik I took inspiration from HTTP implementation.
From what I can see in the other server the current authorizers behaviour is to log and ignore the authorizer if not supported.
In fact this check is only because I want to maintain a common baseline on what is not supported with the HTTP API variant using authFunctionNameExtractor but with Websockets I have to restrict the scope since at the moment only REQUEST authorizers are available.

EDIT: I removed the duplicate check endpoint.authorizer.type in the condition

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarification, it makes sense 👍

@DocLM DocLM force-pushed the feature/websocket-authorizers branch from 3bb0d00 to d940f1f Compare March 15, 2022 18:22
Copy link
Collaborator

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @DocLM 🙇

@pgrzesik pgrzesik changed the title feature: websocket authorizers feat: Support websockets authorizers Mar 15, 2022
@pgrzesik pgrzesik merged commit d3d12df into dherault:master Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants