Skip to content

Commit

Permalink
Added facebook and twitter strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
1602 committed Jul 2, 2012
1 parent e6c2b65 commit 7422960
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
28 changes: 28 additions & 0 deletions lib/strategies/facebook.js
@@ -0,0 +1,28 @@
var passport = require('passport');

exports.callback = function(token, tokenSecret, profile, done) {
User.findOrCreate({
facebookId: profile.id,
profile: profile
}, function (err, user) {
return done(err, user);
});
};

exports.init = function (conf) {
var Strategy = require('passport-facebook').Strategy;
passport.use(new Strategy({
clientID: conf.facebook.apiKey,
clientSecret: conf.facebook.secret,
callbackURL: conf.baseURL + 'auth/facebook/callback'
}, exports.callback));

app.get('/auth/facebook',
passport.authenticate('facebook', { scope: [ 'email' ] }));

app.get('/auth/facebook/callback',
passport.authenticate('facebook', {
failureRedirect: conf.failureRedirect || '/'
}), exports.redirectOnSuccess);

};
28 changes: 28 additions & 0 deletions lib/strategies/twitter.js
@@ -0,0 +1,28 @@
var passport = require('passport');

exports.callback = function(token, tokenSecret, profile, done) {
User.findOrCreate({
twitterId: profile.id,
profile: profile
}, function (err, user) {
return done(err, user);
});
};

exports.init = function (conf) {
var Strategy = require('passport-twitter').Strategy;
passport.use(new Strategy({
consumerKey: conf.twitter.apiKey,
consumerSecret: conf.twitter.secret,
callbackURL: conf.baseURL + 'auth/twitter/callback'
}, exports.callback));

app.get('/auth/twitter',
passport.authenticate('twitter'));

app.get('/auth/twitter/callback',
passport.authenticate('twitter', {
failureRedirect: conf.failureRedirect || '/'
}), exports.redirectOnSuccess);

};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Anatoliy Chakkaev <rpm1602@gmail.com>",
"name": "railway-passport",
"description": "PassportJS integrated with Railway",
"version": "0.0.1",
"version": "0.0.3",
"repository": {
"type": "git",
"url": "git@github.com:1602/Railway-passport.git"
Expand Down

0 comments on commit 7422960

Please sign in to comment.