Skip to content

Instantly share code, notes, and snippets.

@shime shime/
Last active Nov 11, 2019

What would you like to do?
github oauth in node using express


Most basic example of authenticating with Github in node.


Clone this gist, change keys inside config.js and then hit npm install && node app.js.


Now hit this URL: http://localhost:9292/auth/github

var express = require("express"),
app = express(),
config = require("./config.js")
port = 9292;
var githubOAuth = require('github-oauth')({
githubClient: config.GITHUB_KEY,
githubSecret: config.GITHUB_SECRET,
baseURL: 'http://localhost:' + port,
loginURI: '/auth/github',
callbackURI: '/auth/github/callback'
app.get("/auth/github", function(req, res){
console.log("started oauth");
return githubOAuth.login(req, res);
app.get("/auth/github/callback", function(req, res){
console.log("received callback");
return githubOAuth.callback(req, res);
githubOAuth.on('error', function(err) {
console.error('there was a login error', err)
githubOAuth.on('token', function(token, serverResponse) {
var server = app.listen(port, function() {
console.log('Listening on port %d', server.address().port);
module.exports = {
'GITHUB_KEY': 'your-github-key-here',
'GITHUB_SECRET': 'your-github-secret-here'
"name": "example",
"dependencies": {
"express": "4.x.x",
"github-oauth": "0.x.x"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.