OAuth GitHub Gatekeeper
API
-
Exchage temporary code for a token
GET /api/auth?code=<CODE>
OAuth Steps
Also see the documentation on Github.
-
Redirect users to request GitHub access.
GET https://github.com/login/oauth/authorize
-
GitHub redirects back to your site including a temporary code you need for the next step.
You can grab it like so:
const params = locationsearchconst code = params -
Request the actual token using your instance of Gatekeeper, which knows your
OAUTH_CLIENT_SECRET
.const GITHUB_GATEKEEPER_URL = processenvNODE_ENV === 'development'? 'http://localhost:3000/api/auth': 'https://gatekeeper.YOUNAME.now.sh/api/auth'const url = GITHUB_GATEKEEPER_URLurlsearchParamstryconst res = awaitif resokconst token = await resconsolecatch e// bad code
Setup your Gatekeeper
-
Clone it
git clone git@github.com:kobzarvs/github-gatekeeper.git
-
Install Dependencies
cd gatekeeper && yarn
-
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
-
Add secrets env variables
now secrets add OAUTH_CLIENT_SECRET <OAUTH_CLIENT_SECRET> now secrets add OAUTH_CLIENT_ID <OAUTH_CLIENT_ID>
-
Deploy service
now