Giter VIP home page Giter VIP logo

graphql-authentication's Introduction

GraphQL Authentication with JWT

Example project to implement an OAuth 2.0 (Google) with Passport & GraphQL with Apollo V2 and Express over json web tokens.

Version 2 now with:

  • Graphql refactored schemas
  • Apollo V2
  • Babel 7
  • Jest (instead of Mocha)

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

  • Node v10.4.1 or above
  • Mongo database
  • Google+ API Setup

Installing

Clone

git clone https://github.com/antoniojps/graphql-authentication.git

Install dependencies

cd graphql-authentication
npm i

Setup the config in /src/setup/config/config.example.json:

  • Rename the file to 'config.json'
  • Add your variables
/src/setup/config/config.json

Run in the development environment

npm run dev

To test if the authentication is working open any of the following routes:

  • Google - /auth/google

They should redirect you to the callback with the user data and token; A cookie is now set with the token

Running the tests

If the above is done correctly running the tests should be as simple as:

npm run test

Make sure to the test variables in the config file /src/setup/config/config.json are setup correctly

Running coding style tests

To clean up the code with eslint run

npm run eslint

Deployment

Make sure you setup the production variables in the platform of your choise, the config.json file only defines variables for the 'development' and 'test' environments.

You need to change the callback routes to redirect to your client in /setup/routes/auth.js

// Replace this
// res.send(resSchema(req.user, res.statusCode))

// With
res.redirect(process.env.CLIENT_ORIGIN)

Build the project with

npm run build

Start the production server

npm start

Built With

Authors

Acknowledgments

graphql-authentication's People

Contributors

dependabot[bot] avatar

Stargazers

 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.