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

Using an Authorization Lambda doesn't include the context in the request #386

Closed
joain946 opened this issue Oct 9, 2020 · 5 comments
Closed
Assignees
Milestone

Comments

@joain946
Copy link

joain946 commented Oct 9, 2020

Basic information

Serverless Java Container version: 1.5.2

Implementations: Jersey

Framework version: Jersey 2.30.1

Frontend service: HTTP API

Deployment method: SAM

Scenario

When a "Lambda Authorizer" (not the "JWT Authorizer") is used then "authorizer" parts of the Json is ignored. This is when API Gateway is used with the newer "HTTP Api" and using 2.0 of the payload format.

Expected behavior

The context fields returned from the Authorization Lambda should be included in the request

Actual behavior

The Authorization part of the request is an empty map after deserialization of the request

Steps to reproduce

  1. Create a HTTP Api in Api Gateway
  2. Use a "Lambda Authorizer" with 2.0 payload format
  3. In the Lambda use "HttpApiV2ProxyRequest"
  4. When accessing the "event.getRequestContext().getAuthorizer()" then this map will not contain any of the context fields returned from the Authorizer Lambda. This is because only "jwt" is supported and not "lambda".

From the "HttpApiV2AuthorizerMap" class:

        @Override
        public HttpApiV2AuthorizerMap deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
            HttpApiV2AuthorizerMap map = new HttpApiV2AuthorizerMap();
            JsonNode node = jsonParser.getCodec().readTree(jsonParser);
            if (node.get(JWT_KEY) != null) {
                HttpApiV2JwtAuthorizer authorizer = LambdaContainerHandler.getObjectMapper().treeToValue(node.get(JWT_KEY), HttpApiV2JwtAuthorizer.class);
                map.putJwtAuthorizer(authorizer);
            }
            // we ignore other, unknown values
            return map;
        }

Http request (some of the headers have been removed)

{
    "version": "2.0",
    "routeKey": "ANY /api/{proxy+}",
    "rawPath": "/api/v1/openapi",
    "rawQueryString": "",
    "headers": {
        "accept": "application/json,*/*"
    },
    "requestContext": {
        "accountId": "514976038597",
        "apiId": "xyz",
        "authorizer": {
            "lambda": {
                "roles": "TestRole1,TestRole2,authenticated",
                "tenant": "BAAS_AX2",
                "user": "xyz"
            }
        },
        "domainName": "xyz.execute-api.us-east-1.amazonaws.com",
        "domainPrefix": "xyz",
        "http": {
            "method": "GET",
            "path": "/api/v1/openapi",
            "protocol": "HTTP/1.1",
            "sourceIp": " 52.3.40.242",
            "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
        },
        "requestId": "UGFVDhAHoAMEPTg=",
        "routeKey": "ANY /api/{proxy+}",
        "stage": "$default",
        "time": "08/Oct/2020:14:03:12 +0000",
        "timeEpoch": 1602165792204
    },
    "pathParameters": {
        "proxy": "v1/openapi"
    },
    "isBase64Encoded": false
}
@sapessi sapessi added this to the Release 1.6 milestone Oct 9, 2020
@sapessi
Copy link
Collaborator

sapessi commented Oct 9, 2020

Thanks for the report @joain946 - Lambda authorizers for HTTP APIs are indeed not supported yet. We'll make sure they are included in release 1.6.

@joain946
Copy link
Author

Any idea on when version 1.6 will be released?

@deki deki modified the milestones: Release 1.6, Release 1.7 Jul 28, 2021
@jackmcguire1
Copy link

bump

@deki
Copy link
Collaborator

deki commented Nov 25, 2021

Is any of you willing to create a pull request for that?

deki added a commit to deki/aws-serverless-java-container that referenced this issue Dec 29, 2021
@deki deki self-assigned this Dec 29, 2021
@deki
Copy link
Collaborator

deki commented Dec 29, 2021

Finally found the time to implement it. @joain946 @jackmcguire1 please review the PR and let me know if you are ok with it...

@deki deki closed this as completed Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants