Skip to content

Commit

Permalink
Merge pull request #105 from senorcris/feature/github
Browse files Browse the repository at this point in the history
Feature/github
  • Loading branch information
cristiandouce committed Mar 30, 2014
2 parents f792ea3 + e74d7d3 commit 0c3e7e6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config/config.sample.json
Expand Up @@ -10,6 +10,11 @@
"clientid" : "yourClientID",
"clientsecret" : "yourClientSecret",
"callback" : "http://127.0.0.1:6789/auth/facebook/callback"
},
"github": {
"clientid" : "yourClientID",
"clientsecret" : "yourClientSecret",
"callback" : "http://127.0.0.1:6789/auth/github/callback"
}
},
"session" : {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -14,7 +14,8 @@
"passport": "~0.1.17",
"passport-facebook": "~0.1.5",
"passport-twitter": "~0.1.5",
"component-type": "component/type"
"component-type": "component/type",
"passport-github": "~0.1.5"
},
"engines": {
"node": ">= 0.8.0",
Expand Down
11 changes: 11 additions & 0 deletions routes/index.js
Expand Up @@ -65,6 +65,17 @@ function Routes (app) {
);
}

if(config.auth.github.clientid.length) {
app.get('/auth/github', passport.authenticate('github'));

app.get('/auth/github/callback',
passport.authenticate('github', {
successRedirect: '/',
failureRedirect: '/'
})
);
}

app.get('/logout', function(req, res){
req.logout();
res.redirect('/');
Expand Down
15 changes: 14 additions & 1 deletion strategy.js
Expand Up @@ -5,7 +5,8 @@

var passport = require('passport')
, TwitterStrategy = require('passport-twitter').Strategy
, FacebookStrategy = require('passport-facebook').Strategy
, FacebookStrategy = require('passport-facebook').Strategy
, GitHubStrategy = require('passport-github').Strategy;

/**
* Expose Authentication Strategy
Expand Down Expand Up @@ -55,5 +56,17 @@ function Strategy (app) {
}
));
}

if(config.auth.github.clientid.length) {
passport.use(new GitHubStrategy({
clientID: config.auth.github.clientid,
clientSecret: config.auth.github.clientsecret,
callbackURL: config.auth.github.callback
},
function(token, tokenSecret, profile, done) {
return done(null, profile);
}
));
}
}

0 comments on commit 0c3e7e6

Please sign in to comment.