npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@goodgamestudios/aws-jwt-authorizer

v0.0.2

Published

A flexible JWT Authorizer for Serverless functions

Downloads

8

Readme

aws-jwt-authorizer

A flexible JWT Authorizer function for AWS Lambda

pipelinecoverage

aws-jwt-authorizer is heavily based Mohamed’s Authorizer and Secrets Manager and Chad’s ggs-serverless-jwt.

This implementation adds the following:

  • The Public Key for JWT verification is:
    • loaded from Secrets Manager
    • using a key derived from the Issuer (iss) in the JWT
    • cached in memory for a configurable amount of time
  • Almost all aspects of the Authorizer are configurable
  • has automated tests

Usage

npm add @goodgamestudios/aws-jwt-authorizer

Then modify your serverless.yml to make use of this. Add the following function with a suitable name:

function:
  ...
  jwt-authorizer:
    handler: @goodgamestudios/aws-jwt-authorizer
    name: service_stage_jwt-authorizer

Define the following environment variables,

provider:
  environment:
    JWT_AUTH_ISSUERS: A space or comma separated, case sensitive list of acceptable issuers
    GAME_STAGE: 'live' or 'test'

    # Optional
    JWT_AUTH_ALGORITHMS: Defaults to 'RS256, RS384, RS512'
    JWT_AUTH_CLOCK_TOLERANCE: 30
    AWS_SECRET_VALUE_TTL: e.g. '10 min', '20s' etc

In your existing functions, do

function:
  app:
    handler: existing_handler.app
    events:
      - http:
          path: "/path"
          method: get
          # This is the important bit!:
          authorizer:
            name: jwt-authorizer
            resultTtlInSeconds: 60
            identitySource: method.request.header.Authorization
            identityValidationExpression: '^Bearer [-0-9a-zA-Z.+/=_]*$'

Advanced usage

createJwtAuthorizer is fully customizable. All arguments are optional.

const createJwtAuthorizer = require('@goodgamestudios/aws-jwt-authorizer/create')

module.exports = createJwtAuthorizer({
  algorithms: 'RS256', // string or array of strings
  issuer: ['myIssuer', 'myOtherIssuer'], // string or array of strings
  clockTolerance: 60,
  getToken(event) {…},
  getPublicKey(event, decodedToken) {…},
  shouldAllow(event, verifiedToken) {…}
})
  • getToken(event) - get the JWT based on event
  • getPublicKey(event, decodedToken) - get the public key based on event and decodedToken. This key will be used to verify the token’s signature.
  • shouldAllow(event, verifiedToken) - return true if access to the requested resource should be allowed, based on the event and verifiedToken