Skip to content

Instantly share code, notes, and snippets.

@sorribas
Last active August 29, 2015 13:57
Show Gist options
  • Save sorribas/9377945 to your computer and use it in GitHub Desktop.
Save sorribas/9377945 to your computer and use it in GitHub Desktop.
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