Coder Social home page Coder Social logo

effector / effector-gatekeeper Goto Github PK

View Code? Open in Web Editor NEW
0.0 6.0 0.0 5 KB

☄️ now.sh stateless function for OAuth GitHub flow then exchange authorization code for a token

Home Page: https://gatekeeper-beryl.now.sh

License: MIT License

TypeScript 93.73% HTML 6.27%

effector-gatekeeper's Introduction

OAuth GitHub Gatekeeper

API

  1. Exchage temporary code for a token

    GET /api/auth?code=<CODE>
    

OAuth Steps

Also see the documentation on Github.

  1. Redirect users to request GitHub access.

    GET https://github.com/login/oauth/authorize
    
  2. GitHub redirects back to your site including a temporary code you need for the next step.

    You can grab it like so:

    const params = new URLSearchParams(location.search)
    const code = params.get('code')
  3. Request the actual token using your instance of Gatekeeper, which knows your OAUTH_CLIENT_SECRET.

    const GITHUB_GATEKEEPER_URL = process.env.NODE_ENV === 'development'
      ? 'http://localhost:3000/api/auth'
      : 'https://gatekeeper.YOUNAME.now.sh/api/auth'
    
    const url = new URL(GITHUB_GATEKEEPER_URL)
    url.searchParams.set('code', code)
    try {
      const res = await fetch(url)
      if (res.ok) {
        const {token} = await res.json()
        console.log(token)
      }
    } catch (e) {
      // bad code
    }

Setup your Gatekeeper

  1. Clone it

    git clone [email protected]:kobzarvs/github-gatekeeper.git
    
  2. Install Dependencies

    cd gatekeeper && yarn
    
  3. Run local dev environment

    First of all you must create .env file:

    OAUTH_CLIENT_SECRET=<OAUTH_CLIENT_SECRET>
    OAUTH_CLIENT_ID=<OAUTH_CLIENT_ID>
    
    now dev
    

Deploy on now.sh

  1. Add secrets env variables

    now secrets add OAUTH_CLIENT_SECRET <OAUTH_CLIENT_SECRET> 
    now secrets add OAUTH_CLIENT_ID <OAUTH_CLIENT_ID>
    
  2. Deploy service

    now
    

effector-gatekeeper's People

Contributors

kobzarvs avatar sergeysova avatar

Watchers

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