Skip to content

feat(aws-node-rest-api-jwt-authorizer): add a REST API example with a JWT authorizer - #833

Open
czubocha wants to merge 2 commits into
v4from
feat/aws-node-rest-api-jwt-authorizer
Open

czubocha wants to merge 2 commits into
v4from
feat/aws-node-rest-api-jwt-authorizer

Conversation

@czubocha

Copy link
Copy Markdown
Contributor

Summary

  • Add aws-node-rest-api-jwt-authorizer: a REST API whose endpoints are protected by a JWT authorizer defined under provider.apiGateway.authorizers, with a Cognito user pool in the same service as the issuer (issuerUrl: !GetAtt UserPool.ProviderURL, audience: !Ref UserPoolClient, algorithms: [rs256]).
  • Routes:
    • GET /hello is public;
    • GET /me takes an ID token;
    • GET /account requires the scope aws.cognito.signin.user.admin (access token).
  • Handlers return the caller's identity. They read event.requestContext.authorizer.claims; where API Gateway doesn't pass claims to the integration, they decode the already-validated token from the Authorization header.
  • The README shows creating a user and getting tokens with the AWS CLI, and curl calls with their outcomes (200, 401, and the token_use reason).
  • test/smoke.mjs runs the same steps for the live test.
  • The root README.md and examples.json are regenerated.

Merge after the Framework release that includes JWT authorizers for REST APIs (serverless/serverless#14153). The live test installs the latest release, so re-run it once that release is out.

Test plan

  • npm run docs, check-examples (0 errors), npm test (308 pass) and npm run validate pass.
  • Live test with test-example.mjs and the Framework from source (feat(aws-api-gateway): add JWT authorizers for REST API http events serverless#14153), in a test account:
    • eu-west-1, claims from requestContext.authorizer.claims;
    • us-east-1, claims decoded from the header;
    • eu-west-1 again, with only the live-test role's permissions.
  • A deliberately changed handler is caught at the check step.
  • The README's steps, run word for word, return the documented status codes.
  • Every stage was removed, and nothing was left behind.

Generated by Claude Code

… JWT authorizer

Protect REST API endpoints with a JWT authorizer under
provider.apiGateway.authorizers that trusts an Amazon Cognito user pool in
the same service, require an OAuth scope on one endpoint, and return the
caller's claims from requestContext.authorizer.claims, decoding the
validated token where API Gateway doesn't pass claims yet.

Copy link
Copy Markdown
Contributor Author

The live test installs the latest release, 4.46.0, which predates JWT authorizers for REST API http events (serverless/serverless#14153). It reads authorizer: users as a function name, so packaging stops before CloudFormation is called, and the remove-only step confirms no stack was created in the stage. This check is expected to pass once it is re-run on the release that includes that change.


Generated by Claude Code

…jwt-authorizer

# Conflicts:
#	README.md
#	examples.json
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.

1 participant