Giter Club home page Giter Club logo

graphql-server-github-auth-example's Introduction

GraphQL Server - Github Auth

This example shows how to implement Github Authentication with GraphQL Server, using graphql-yoga and other tools.

Getting started

Initializing the Graphcool Database service

graphcool deploy # copy simple API endpoint into the `GRAPHCOOL_ENPOINT` env var in .env

Setting up the Github OAuth2

You need to configure these credentials from a new Github OAuth2 app as environment variables:

  • GITHUB_CLIENT_ID
  • GITHUB_CLIENT_SECRET
  1. Go to github.com and navigate to your profile. Click on your profile icon in the upper right corner and enter Settings.
  2. In the lower left side find Developer Settings and navigate to OAuth Apps.
  3. Click New OAuth App and give your app a nice name. For the purposes of the example, it is best to set the Homepage URL to http://localhost:8000 and Authorization callback URL to http://localhost:8000/login. (Application description is optional).
  4. Register the application.
  5. Copy Client ID and Client Secret to the .env file.

Testing with WEB

  • Replace __CLIENT_ID__ in login.html
  • Serve login.html, for example by using python -m SimpleHTTPServer
  • Open https://localhost:8000/login.html in a browser, open the DevTools and authenticate with your Github account
  • Copy the code printed in the Console of your DevTools

Testing with "simple hack"

In order to obtain Github code you can use this little hack.

  1. Navigate to https://github.com/login/oauth/authorize?client_id=<client_id>&scope=user and replace <client_id> with your Github client ID.
  2. Authorise access to the account and you will be redirected to localhost:8000/login.html?code=<github_code>.
  3. Copy the <github_code> to your GraphQL playground where you can test authentication.

Starting the Server

yarn install
yarn start
# Open http://localhost:5000/

License

MIT

graphql-server-github-auth-example's People

Contributors

marktani avatar maticzav avatar

Watchers

 avatar  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.