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

Use Cognito as JWT Authorizer with HTTP API? #1058

Closed
webpepper opened this issue Aug 5, 2020 · 3 comments
Closed

Use Cognito as JWT Authorizer with HTTP API? #1058

webpepper opened this issue Aug 5, 2020 · 3 comments

Comments

@webpepper
Copy link

Is using Cognito as JWT Authorizer with HTTP API currently supported by serverless-offline?

I'm trying to figure out if it's an issue in my config or something that this plugin currently doesn't support.

In Lambda, Amazon API Gateway REST API claims can be obtained from event.requestContext.authorizer.claims.

However, HTTP API (API Gateway v2) puts them into event.requestContext.authorizer.jwt.claims (one level deeper under jwt).

I send custom JWT tokens and I can see them getting parsed and set under authorizer.claims. But how can I set this authorizer.jwt property and put claims inside of it?

Sure I can use process.env.IS_OFFLINE and extract one or the other, but it just ain't pretty.

let email;
if (process.env.IS_OFFLINE) {
  email = event.requestContext.authorizer.claims.email;
} else {
  email = event.requestContext.authorizer.jwt.claims.email;
}

Enviroment: Lambda (Node.js)

@lmmattr
Copy link

lmmattr commented Dec 16, 2020

I've just hit this too. Lambda output gives the event.requestContext.authorizer.jwt.claims format. and offline gives event.requestContext.authorizer.claims

For context, im using:
"serverless": "^2.15.0",
"serverless-offline": "^6.8.0"

@lmmattr
Copy link

lmmattr commented Dec 16, 2020

As a workaround to this i'm going to use the custom authorizers variable you can add to the environment:

AUTHORIZER={"jwt": {"claims":{...}}}

@gavinsharp
Copy link

I think this was fixed by #1092

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

No branches or pull requests

4 participants