Created
August 13, 2013 20:56
-
-
Save elisee/6225599 to your computer and use it in GitHub Desktop.
Handling Facebook App Center auto-login request with express and passport-facebook (in CoffeeScript)
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
# ... Do your usual Facebook passport strategy setup here ... | |
# Handle GET on / | |
app.get "/", (req, res, next) -> | |
if req.isAuthenticated() | |
# ... Render logged in page ... | |
else | |
# Check for Facebook app center login | |
if req.query.code? and req.query.fb_source? | |
# The callback URL *must* be the same as the request URL minus the "code" variable | |
callbackQuery = {} | |
for key, value of req.query | |
if key != 'code' | |
callbackQuery[key] = value | |
doAuth = passport.authenticate('facebook', { callbackURL: 'http://example.com/?' + querystring.stringify(callbackQuery) } ) | |
doAuth req, res, -> res.redirect '/' | |
return | |
# Not a Facebook login request | |
# ... Render logged out page ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment