Skip to content

Instantly share code, notes, and snippets.

@elisee
Created August 13, 2013 20:56
Show Gist options
  • Save elisee/6225599 to your computer and use it in GitHub Desktop.
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)
# ... 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