Giter VIP home page Giter VIP logo

passport-js-auth-webhook's Introduction

Passport.js Auth Webhook example for Hasura GraphQL engine

This is a sample auth webhook for authenticating requests to the Hasura GraphQL engine.

Prerequisites

Getting Started

The easiest way to get started is to clone the repository:

# Get the latest snapshot
git clone [email protected]:hasura/graphql-engine.git myproject

# Change directory
cd myproject/community/boilerplates/auth-webhooks/passport-js-auth-webhook

# Install NPM dependencies
npm install

# Set DATABASE_URL env
export DATABASE_URL=postgres://<username>:<password>@<host>:<port>/<database_name>

# Apply migrations
knex migrate:latest

# Then simply start your app
npm start

Deploy with Heroku (recommended)

  1. Follow the below steps to deploy with heroku:

    # Create heroku app
    heroku create <app-name>
    
    # Create PostgreSQL addon
    heroku addons:create heroku-postgresql:hobby-dev -a <app-name>
    
    # Push changes to heroku
    git push heroku master
    
    # Run Apply migrations
    heroku run knex migrate:latest
  2. Once it is deployed, we can create an user using /signup API like below:

   curl --header "Content-Type: application/json" \
    --request POST \
    --data '{"username": "test123", "password": "test123", "confirmPassword": "test123"}' \
    http://localhost:8080/signup
  1. On signup, we get below response:
  {
    "id": 1,
    "username": "[email protected]",
    "token": "4ffd5ee92853787836325dcea74c02e4"
  }
  1. Also, we can use /login API to fetch the user token,
   curl --header "Content-Type: application/json" \
    --request POST \
    --data '{"username": "test123", "password": "test123"}' \
    http://localhost:8080/login
  1. Webhook is available at /webhook API which accepts Authorization header to validate the token against an user.

Usage with Hasura GraphQL engine

Once you have deployed this webhook, you can use it along with the GraphQL engine. You have to set the webhook URL as an environment variable in the docker container that runs the GraphQL engine.

Read the docs.

Send the token as a header while making queries to the graphql-engine

{
  "Authorization": "Bearer <token>"
}

passport-js-auth-webhook's People

Contributors

arvi3411301 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.