Giter Site home page Giter Site logo

lambda-authorizer-jwt's Introduction

JWT Token Lambda Authorizer

Changes:

  • added support for (AWS API Gateway) websockets authorization
  • added support for (legacy) websocket clients (auth via queryParam)

Overview

This function uses the jwks-rsa and jsonwebtoken npm packages to implement token validation of JSON Web Tokens (JWTs). These tokens are granted by ID Providers using the OAuth2 protocol.

The authorizer expects to find a JWT in the Authorization header.

The public RSA256 key(s) from the Identity Provider are fetched and cached. The JWT is then validated with the public RSA key without further HTTP calls. This means that there is no token introspection performed at the ID Provider server. This allows the authorizer to perform authorization based on signed, unexpired tokens that contain the required issuer and audience credentials per OIDC spec. This also enables extremely low latency times for invoking the AWS API Gateway calls to protected resources.

Deployment

Upload the .zip file to AWS Lambda in the same region as the API Gateway resources you intend to protect with this authorizer.

Configuration

Two environment variables must be set when you deploy the function to AWS:

  • RESOURCE
    • the AWS arn for the API Gateway endpoint(s) you intend to secure with this Lambda Authorizer
  • JWKS_URI
    • the uri to retrieve the public signing keys at your Identity Provider (this can usually be found at the OAuth2/OIDC server discovery endpoint)

Additional Security

The function as-is will validate the JWT claims by checking the JWT signature against the IdP public RSA key. This provides assurance that the claims in the JWT can be trusted, but there is no logic that restricts access based on the JWT claims.

As-is, this function will allow access to the specified arn resource to any bearer of a valid JWT.

As-is, this function allows access to all users regardless of issuer, scope, and intended audience claims.

It is best practice to implement fine-grained authorization to access protected resources based on these claims.

Refer to AWS API Gateway Lambda Authorizers Documentation for more in-depth documentation about use of Lambda Authorizers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.