https://github.com/effector/effector-gatekeeper
☄️ now.sh stateless function for OAuth GitHub flow then exchange authorization code for a token
https://github.com/effector/effector-gatekeeper
Last synced: over 1 year ago
JSON representation
☄️ now.sh stateless function for OAuth GitHub flow then exchange authorization code for a token
- Host: GitHub
- URL: https://github.com/effector/effector-gatekeeper
- Owner: effector
- License: mit
- Created: 2020-03-31T13:31:08.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-31T14:01:02.000Z (about 6 years ago)
- Last Synced: 2024-10-29T18:37:11.185Z (over 1 year ago)
- Language: TypeScript
- Homepage: https://gatekeeper-beryl.now.sh
- Size: 4.88 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
OAuth GitHub Gatekeeper
=======================
## API
1. Exchage temporary code for a token
```
GET /api/auth?code=
```
## OAuth Steps
Also see the [documentation on Github](http://developer.github.com/v3/oauth/).
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:
```js
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`.
```js
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 git@github.com: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_ID=
```
```
now dev
```
## Deploy on now.sh
1. Add secrets env variables
```
now secrets add OAUTH_CLIENT_SECRET
now secrets add OAUTH_CLIENT_ID
```
2. Deploy service
```
now
```