Skip to content

feat(apigatewayv2): Lambda authorizer for WebSocket API - #16886

Merged
mergify[bot] merged 16 commits into
aws:masterfrom
tmokmss:websocket_authorizer2
Dec 14, 2021
Merged

mergify[bot] merged 16 commits into
aws:masterfrom
tmokmss:websocket_authorizer2

Conversation

@tmokmss

@tmokmss tmokmss commented Oct 9, 2021 •

Copy link
Copy Markdown
Contributor

closes #13869

By this PR, you will be able to enable WebSocket authorizer as the below code:

    const integration = new LambdaWebSocketIntegration({
      handler,
    });
    const authorizer = new WebSocketLambdaAuthorizer('Authorizer', authHandler);
    new WebSocketApi(stack, 'WebSocketApi', {
      connectRouteOptions: {
        integration,
        authorizer,
      },
    });

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io

gitpod-io Bot commented Oct 9, 2021

Copy link
Copy Markdown

@tmokmss tmokmss changed the title feat(apigatewayv2): websocket authorizer feat(apigatewayv2): Lambda authorizer for WebSocket API Oct 9, 2021
@peterwoodworth peterwoodworth changed the title feat(apigatewayv2): Lambda authorizer for WebSocket API feat(apigatewayv2): Lambda authorizer for WebSocket API Oct 21, 2021
@github-actions github-actions Bot added the @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 label Oct 21, 2021
@Dzhuneyt

Copy link
Copy Markdown
Contributor

This is perfect! Exactly what I need right now. I was planning to start a PR for myself.

Any chance we can prioritize this?

@nija-at nija-at added effort/medium Medium work item – several days of effort p2 labels Nov 5, 2021
@nija-at nija-at removed their assignment Nov 5, 2021
@otaviomacedo otaviomacedo self-assigned this Dec 13, 2021
'$request.header.Authorization',
],
type: WebSocketAuthorizerType.LAMBDA,
authorizerName: this.props.authorizerName,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should fall back to the new id constructor arg.

/**
* The name of the authorizer
*/
readonly authorizerName: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We need to make this API consistent with HttpLambdaAuthorizer/HttpLambdaAuthorizerProps:

  1. Move handler to the constructor of WebSocketLambdaAuthorizer.
  2. Pass an id to the constructor of WebSocketLambdaAuthorizer.

const id = this.props.authorizerName;

this.webSocketApi = options.route.webSocketApi;
this.authorizer = new WebSocketAuthorizer(options.scope, id, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When you add the new id constructor arg, replace id with this.id.

@tmokmss
tmokmss marked this pull request as draft December 14, 2021 13:43
@mergify
mergify Bot dismissed otaviomacedo’s stale review December 14, 2021 13:44

Pull request has been modified.

@tmokmss
tmokmss marked this pull request as ready for review December 14, 2021 14:46
@tmokmss

tmokmss commented Dec 14, 2021

Copy link
Copy Markdown
Contributor Author

@otaviomacedo
Hi, thanks for the review. I fixed the API to be more consistent with httpApi.
Also I updated README.md for apigatewayv2-authorizers. I'd appreciate if you could review again when you get a chance.

@otaviomacedo otaviomacedo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks 👍

@mergify

mergify Bot commented Dec 14, 2021

Copy link
Copy Markdown
Contributor

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation

Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 6e88ddf
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
mergify Bot merged commit 67cce37 into aws:master Dec 14, 2021
@mergify

mergify Bot commented Dec 14, 2021

Copy link
Copy Markdown
Contributor

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@tmokmss
tmokmss deleted the websocket_authorizer2 branch December 15, 2021 02:31
mergify Bot pushed a commit that referenced this pull request Jan 7, 2022
… `WebSocketLambdaAuthorizer` (#18315)

We introduced `WebSocketLambdaAuthorizer` in #16886 with an incorrect default `identitySource`, according to these [docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-authorizer.html#cfn-apigatewayv2-authorizer-identitysource). The result is that using the default `identitySource` results in a deploy-time failure.

This PR fixes the error and adds documentation for the syntax for all `identitySource` possibilities.

I can confirm that this default successfully passes `cdk deploy` on my local app.

Fixes #18307. 

BREAKING CHANGE: `WebSocketLambdaAuthorizerProps.identitySource` default changes from `['$request.header.Authorization']` to `['route.request.header.Authorization']`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
closes aws#13869

By this PR, you will be able to enable WebSocket authorizer as the below code:

```ts
    const integration = new LambdaWebSocketIntegration({
      handler,
    });
    const authorizer = new WebSocketLambdaAuthorizer('Authorizer', authHandler);
    new WebSocketApi(stack, 'WebSocketApi', {
      connectRouteOptions: {
        integration,
        authorizer,
      },
    });
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
… `WebSocketLambdaAuthorizer` (aws#18315)

We introduced `WebSocketLambdaAuthorizer` in aws#16886 with an incorrect default `identitySource`, according to these [docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-authorizer.html#cfn-apigatewayv2-authorizer-identitysource). The result is that using the default `identitySource` results in a deploy-time failure.

This PR fixes the error and adds documentation for the syntax for all `identitySource` possibilities.

I can confirm that this default successfully passes `cdk deploy` on my local app.

Fixes aws#18307. 

BREAKING CHANGE: `WebSocketLambdaAuthorizerProps.identitySource` default changes from `['$request.header.Authorization']` to `['route.request.header.Authorization']`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
ali-n4i pushed a commit to ali-n4i/aws-cdk that referenced this pull request Jul 29, 2026
closes aws#13869

By this PR, you will be able to enable WebSocket authorizer as the below code:

```ts
    const integration = new LambdaWebSocketIntegration({
      handler,
    });
    const authorizer = new WebSocketLambdaAuthorizer('Authorizer', authHandler);
    new WebSocketApi(stack, 'WebSocketApi', {
      connectRouteOptions: {
        integration,
        authorizer,
      },
    });
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
ali-n4i pushed a commit to ali-n4i/aws-cdk that referenced this pull request Jul 29, 2026
… `WebSocketLambdaAuthorizer` (aws#18315)

We introduced `WebSocketLambdaAuthorizer` in aws#16886 with an incorrect default `identitySource`, according to these [docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-authorizer.html#cfn-apigatewayv2-authorizer-identitysource). The result is that using the default `identitySource` results in a deploy-time failure.

This PR fixes the error and adds documentation for the syntax for all `identitySource` possibilities.

I can confirm that this default successfully passes `cdk deploy` on my local app.

Fixes aws#18307. 

BREAKING CHANGE: `WebSocketLambdaAuthorizerProps.identitySource` default changes from `['$request.header.Authorization']` to `['route.request.header.Authorization']`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 effort/medium Medium work item – several days of effort p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(apigatewayv2): Allow to set Lambda authorizer for WebSocket API

5 participants