Last active
August 29, 2015 13:57
-
-
Save sorribas/9377945 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var root = require('root'); | |
var github = require('github-auth'); | |
var app = root(); | |
var gh = github('blah', 'blehbleh', { | |
users: ['sorribas'] | |
}); | |
app.get('/login', function(req, res) { | |
res.send('<a href="'+gh.loginUrl+'">Login</a>'); | |
}); | |
app.all('*', gh.authenticate); | |
app.all('*', function(req, res, next) { | |
if (!req.github) return res.redirect('/login'); | |
if (!req.github.authenticated) return res.send('You shall not pass'); | |
next(); | |
}); | |
app.get('/', function(req, res) { | |
res.send('<h2>Hello World!</h2>'); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment