Created
October 8, 2012 21:00
-
-
Save jaredhanson/3854950 to your computer and use it in GitHub Desktop.
Sketch RelMeAuth strategy for Passport
This file contains hidden or 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
// mapping relmeauth provider support to local URLs for initiating | |
// authentication, using OAuth, OAuth 2.0, or just about anything else | |
passport.use(new RelmeStrategy({ | |
'twitter.com': '/auth/twitter' | |
'facebook.com': '/auth/facebook' | |
}, | |
function(token, profile, done) { | |
// relme auth is mostly a discovery mechanism, which redirects | |
// the the highest-priority, supported provider. The verify | |
// callback would likely be handled best by the configured | |
// FacebookStrategy, TwitterStrategy, etc. Having a verify | |
// callback here is debatable, and likely not needed | |
} | |
)); | |
passport.use(new TwitterStrategy({ | |
consumerKey: TWITTER_CONSUMER_KEY, | |
consumerSecret: TWITTER_CONSUMER_SECRET, | |
callbackURL: "http://127.0.0.1:3000/auth/twitter/callback" | |
}, | |
associateOAuthUser | |
)); | |
passport.use(new FacebookStrategy({ | |
clientID: FACEBOOK_APP_ID, | |
clientSecret: FACEBOOK_APP_SECRET, | |
callbackURL: "http://localhost:3000/auth/facebook/callback" | |
}, | |
associateOAuth2User | |
)); | |
// Mount the protocol routes. This can be trivially wrapped in a single | |
// function if it seems too boilerplate. | |
app.get('/auth/facebook', passport.authenticate('facebook')); | |
app.get('/auth/facebook/callback', passport.authenticate('facebook', { successRedirect: '/', | |
failureRedirect: '/login' })); | |
app.get('/auth/twitter', passport.authenticate('twitter')); | |
app.get('/auth/twitter/callback', passport.authenticate('twitter', { successRedirect: '/', | |
failureRedirect: '/login' })); | |
app.post('/auth/relme', passport.authenticate('relme')); | |
app.get('/login', /* render the following form */); | |
<form action="/auth/relme" method="post"> | |
<div> | |
<label>yourdomain.com:</label> | |
<input type="text" name="me"/><br/> | |
</div> | |
<div> | |
<input type="submit" value="Submit"/> | |
</div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment