• Stars
    star
    729
  • Rank 61,917 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tiny microservice that makes adding authentication with GitHub to your application easy.

micro-github

A tiny microservice that makes adding authentication with GitHub to your application easy.

Usage

Running your own micro-github is a single now command away:

# Deploy this repository using now.sh
now mxstbr/micro-github -e GH_CLIENT_ID=xyz123 -e GH_CLIENT_SECRET=asdf123 -e REDIRECT_URL=https://google.com

Environment variables

You'll need to provide three environment variables when running micro-github:

# Your GitHub application client id
GH_CLIENT_ID=xyz123
# Your GitHub application client secret
GH_CLIENT_SECRET=asdf123
# The URL to redirect the user to once the authentication was successful
REDIRECT_URL=https://google.com
# Optional: Specify the GitHub host when using GitHub Enterprise
GH_HOST=github.my-company.com

Create an application on GitHub here to get your client id and secret if you haven't done that already.

When authentication is successful, the user will be redirected to the REDIRECT_URL with the access_token query param set to the GitHub access token. You can then use that token to interact with the GitHub API!

E.g. setting REDIRECT_URL=https://google.com will redirect them to https://google.com/?access_token=asdf123. (where asdf123 is the provided access token)

Finish setup

To make this work you have to set the authorization callback URL of your application on GitHub to whatever URL now gave you plus the path /callback e.g. http://localhost:3000/callback:

Authorization callback URL: 'your-url.now.sh'

To log people in provide a link to url now gave you plus the path login e.g. http://localhost:3000/login when they click on the link it will redirect to https://github.com/login/oauth/authorize?client_id=asdf123&state. (where client_id is your GitHub app client id in .env and state is a randomly generated string). This will redirect them to the GitHub sign in page for your app, which looks like this:

Authorize my app to access your data on GitHub

You can change the scope of the data you can access with the scope query param, see the GitHub docs!

When authentication is successful, the user will be redirected to the REDIRECT_URL with the access token from GitHub for you to use! 🎉

Error handling

In case an error happens (either by the service or on GitHub) the user will be redirected to the REDIRECT_URL with the error query param set to a relevant error message.

Development

git clone [email protected]:mxstbr/micro-github.git

Move .env.example to .env and fill in your GitHub API details and redirect url

npm run dev

The server will then be listening at localhost:3000, so set the authorization callback URL of your dev application on GitHub to http://localhost:3000/callback.

Updating

The master branch of this repository is what you will be deploying. To update to a new version with potential bugfixes, all you have to do is run the now command again and then set the authorization callback URL on GitHub to the new URL that now gave you! 👌

License

Copyright (c) 2017 Maximilian Stoiber, licensed under the MIT license. See LICENSE.md for more information.

More Repositories

1

sharingbuttons.io

Quickly generate social sharing buttons with a tiny performance footprint
JavaScript
2,473
star
2

login-flow

🔑 A login/register flow built with React&Redux
JavaScript
1,610
star
3

passport-magic-login

Passwordless authentication with magic links for Passport.js.
TypeScript
664
star
4

mxstbr.com

The source for my personal website
JavaScript
438
star
5

karabiner

My Karabiner Elements configuration
TypeScript
106
star
6

fifteen-kilos

Fifteen kilos
JavaScript
82
star
7

awesome-austria

🇦🇹 A curated list of things that show the awesome side of Austria
JavaScript
75
star
8

markdown-test-file

A pure markdown test page to make sure your markdown support works as intended
58
star
9

pgp.asc

An initiative to decentralize public PGP keys.
HTML
56
star
10

postcss.parts

A searchable catalog of PostCSS plugins —
JavaScript
46
star
11

eslint-plugin-clean-styled-components

Lint your styled-components code to be clean
JavaScript
40
star
12

urql-exchange-schema

Hey Berlin! This is new
TypeScript
31
star
13

knowledge

💡 Document everything (inspired by @yoshuawuyts)
31
star
14

dotfiles

My dotfiles
Vim Script
23
star
15

styling-workshop

Styling React applications workshop
JavaScript
17
star
16

github-markdown-tricks

A collection of tricks one can use in Github Markdown
16
star
17

pokedex

An example React app built "the old way"
JavaScript
14
star
18

modern-react-workshop

JavaScript
13
star
19

create-vcard

Create a vCard from an object. Simple wrapper around vcards-js.
JavaScript
13
star
20

teapot

A simple teapot server in Go
Go
11
star
21

mxstbr.github.io

My old blog
SCSS
10
star
22

old-personal-website

[DEPRECATED] See https://github.com/mxstbr/mxstbr.com for the current version!
PostScript
7
star
23

digitalgarden

TypeScript
6
star
24

elixir-graphql-test

Nothing to see here, just learning some new stuff
Elixir
6
star
25

mxstbr

5
star
26

hoc-benchmark

JavaScript
5
star
27

sw-demo

Simple ServiceWorker demo
JavaScript
5
star
28

speaking

5
star
29

serverless-graphql-airtable-extended

Extended version of https://github.com/ibrahima92/serverless-graphql-airtable
JavaScript
4
star
30

first-website

The first website I ever published for myself
CSS
4
star
31

eslint-plugin-styled-components

An eslint plugin to lint styled-components CSS
JavaScript
4
star
32

wwc

React Workshop for Women Who Code London
HTML
4
star
33

modern-react

3
star
34

scrolled

A tiny library which adds a class on page load and when the user has scrolled.
JavaScript
3
star
35

jschat

JavaScript
3
star
36

workshops-website

Sample DatoCMS website built with GatsbyJS
JavaScript
3
star
37

cyclejs-counter

Hello from the GraphCDN demo!
TypeScript
2
star
38

cool-group-site

Just a test
CSS
2
star
39

nextjs-decap-cms-blog-template

TypeScript
2
star
40

eternalpad

One-off, device specific notes —
ApacheConf
2
star
41

postcss-viennajs

A PostCSS plugin to demonstrate how to write a PostCSS plugin
JavaScript
2
star
42

workshop

HTML
2
star
43

debug.css

Easily debug your CSS positioning issues
CSS
1
star
44

viennajs-sw-demo

JavaScript
1
star
45

convertr

Chrome extension which converts units on webpages to ones you actually understand.
JavaScript
1
star
46

graphql-functions-example

JavaScript
1
star
47

weather-app

HTML
1
star
48

memory

A memory game in Valentines Day style, written with PaperJS.
JavaScript
1
star
49

react-boilerplate-cli

CLI for react-boilerplate
1
star