Git Product home page Git Product logo

serverless-auth0-authorizer's Introduction


codingly.io

Serverless Framework Auth0 Authorizer

A modern, ES6-friendly Lambda Authorizer ready for integration with Serverless Framework and Auth0.
Based on the serverless/examples/aws-node-auth0-custom-authorizers-api example.

Features

  • Test front-end application
  • Private endpoint for testing
  • Public endpoint for testing
  • ES6-friendly

Getting started

1. Clone the repository (or generate a serverless project)

sls create --name auth-service --template-url https://github.com/codingly-io/serverless-auth0-authorizer
cd auth-service

2. Install dependencies

npm install

3. Create secret.pem file

This file will contain your Auth0 public certificate, used to verify tokens.

Create a secret.pem file in the root folder of this project. Simply paste your public certificate in there.

4. Deploy the stack

We need to deploy the stack in order to consume the private/public testing endpoints.

sls deploy -v

5. Final test

To make sure everything works, send a POST request (using curl, Postman etc.) to your private endpoint.

You can grab a test token from Auth0. Make sure to provide your token in the headers like so:

"Authorization": "Bearer YOUR_TOKEN"

You should be good to go!


Bonus: Cross-stack authorization

This is very useful in a microservices setup. For example, you have an Auth Service (this service) which owns anything auth/user-related, and a bunch of other services that require user authorization. Fear not, it is very easy to make your authorizer work anywhere else in your AWS account.

When defining your Lambdas in other services, simply define the authorizer as well and provide the ARN of your auth function (can be found in the AWS Console or via sls info).

Example:

functions:
  someFunction:
    handler: src/handlers/someFunction.handler
    events:
      - http:
          method: POST
          path: /something
          authorizer: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:sls-auth-service-draft-dev-auth

If everything was set up correctly, all incoming requests to your someFunction Lambda will first be authorized. You can find the JWT claims at event.requestContext.authorizer.

serverless-auth0-authorizer's People

Contributors

arielweinberger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

serverless-auth0-authorizer's Issues

on the frontend, this doesn't work... our api only accepts id_tokens...

Hi buddy,

I was hoping you might be able to solve something with me.

  • Our API only accepts the id_tokens,
  • Auth0 client libraries for react and Nextjs only give access tokens
  • Our API always returns unauthorized or 500 server errors or null when sending access tokens.
  • So we are stuck at the moment when trying to setup a frontend.

Please if you could take a look and find a way to get this auth service working friendly with the latest auth0 client packages would be a massive help. I've been stuck on this issue for over 24 hours... my brain is in pain.

Bests,

Sean.

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.