Skip to content

Instantly share code, notes, and snippets.

@alfredwesterveld
Created June 22, 2011 02:35
Show Gist options
  • Save alfredwesterveld/1039402 to your computer and use it in GitHub Desktop.
Save alfredwesterveld/1039402 to your computer and use it in GitHub Desktop.
app.js
Directory layout
----------------
app.js
views/layout.jade
views/home.jade
Configure
-----------------
Setup settings at Facebook and FacebookId and FacebookSecret in app.js. Also make sure you map `Site URL` correctly at Facebook and in app.js.
var express = require('express'),
app = null,
everyauth = require('everyauth'),
id = '', // FacebookId
secret = '', // Facebooksecret
usersByFbId = {};
everyauth.debug = true;
everyauth
.facebook
.appId(id)
.appSecret(secret)
.handleAuthCallbackError( function (req, res) {
// If a user denies your app, Facebook will redirect the user to
// /auth/facebook/callback?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.
// This configurable route handler defines how you want to respond to
// that.
// If you do not configure this, everyauth renders a default fallback
// view notifying the user that their authentication failed and why.
console.log('fail');
})
.findOrCreateUser( function (session, accessToken, accessTokExtra, fbUserMetadata) {
// find or create user logic goes here
return usersByFbId[fbUserMetadata.id] ||
(usersByFbId[fbUserMetadata.id] = fbUserMetadata);
})
.redirectPath('/');
app = express.createServer(
express.bodyParser(),
express.static(__dirname + "/public"),
express.cookieParser(),
express.session({ secret: 'htuayreve'}),
everyauth.middleware()
);
app.get('/', function (req, res) {
res.render('home.jade');
});
everyauth.helpExpress(app);
app.listen(8000, 'localhost');
!!! 5
html
head
title= typeof(title) !== 'undefined' ? title : "everyauth example"
script(src='http://static.ak.fbcdn.net/connect/en_US/core.js')
body
h1 everyauth Example
#main
!= body
- if (!everyauth.loggedIn)
h2 Not Authenticated
#fb-login.fb_button(style='background-position: left -188px')
a.fb_button_medium(href='/auth/facebook')
span#fb_login_text.fb_button_text
Connect with Facebook
- else
h2 Authenticated
- if (everyauth.facebook)
h3 Facebook User Data
p= JSON.stringify(everyauth.facebook.user)
h3
a(href='/logout') Logout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment