Giter Site home page Giter Site logo

auth0-aws-lambda-authorizer's Introduction

AWS Lambda authorizer example with Auth0

This example application deploys an AWS API Gateway with two AWS Lambda functions:

  • a Token type authorizer lambda (contains JWT token authentication)
  • and a hello lambda secured by the lambda authorizer (a valid JWT token is needed to call it)

Deploy the application

Prerequisite

  • Install serverless framework on your local
  • Create an Auth0 account and a new tenant (tenant name e.g.: qwertz543210)

New Tenant

  • In Auth0 dashboard go to APIs -> API explorer and create a test application to use the API Explorer.

New API

  • After creating the test application a test token should appear on the page. Copy it and replace <TOKEN> in the invoke-secure-lambda.sh below.
  • Fill in the ./src/env.yml file. Using the qwertz543210 tenant we created the file should look like this:
JWKS_URI: https://qwertz543210.auth0.com/.well-known/jwks.json
AUDIENCE: https://qwertz543210.auth0.com/api/v2/
TOKEN_ISSUER: https://qwertz543210.auth0.com/

Deploy with serverless framework

cd src/jwt-lambda-authorizer
npm i
cd ../../

serverless deploy --region eu-west-1

Call the secured endpoint

Call the /hello endpoint with curl. Open invoke-secure-lambda.sh and replace the followings:

  • <TOKEN> - this should be replaced by now (see previous steps)
  • <API_GATEWAY_URL> - You will find this in AWS API Gateway console under Stages.

NOTE: my stage is dev

curl -X GET \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer <TOKEN>" \
     https://<API_GATEWAY_URL>/dev/hello?name=thisIsPassedToTheLambda

Remove the application

serverless remove --region eu-west-1

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.