Browse files

Everyauth doesn't work yet...but it's close. I'm going to rip some th…

…ings apart now
  • Loading branch information...
1 parent 664c1d3 commit 032a2af2edffe15fe5c3041fcc5b42a7457f663a @abelmartin committed Sep 18, 2011
Showing with 58 additions and 48 deletions.
  1. +48 −37 app.js
  2. +1 −1 package.json
  3. +9 −10 views/layout.jade
View
85 app.js
@@ -1,30 +1,59 @@
-/**
- * Module dependencies.
- */
+
+// Module dependencies.
var express = require('express'),
- auth = require('connect-auth'),
- twitKey = "809JiWRofheAvdYgO4ACA",
- twitSec = "tNe4jr0aCiPRe52QVsVY1IJsZKcesf3ORyabmfQ6Ms";
+ /*connect = require('connect'),*/
+ everyauth = require('everyauth'),
+ /*auth = require('connect-auth'),*/
+ conf = require('./conf');
+
+var usersById = {};
+var nextUserId = 0;
+
+function addUser (source, sourceUser) {
+ var user;
+ if (arguments.length === 1) { // password-based
+ user = sourceUser = source;
+ user.id = ++nextUserId;
+ return usersById[nextUserId] = user;
+ } else { // non-password-based
+ user = usersById[++nextUserId] = {id: nextUserId};
+ user[source] = sourceUser;
+ }
+ return user;
+}
+
+everyauth.debug = true;
+
+everyauth
+ .twitter
+ .consumerKey(conf.twit.consumerKey)
+ .consumerSecret(conf.twit.consumerSecret)
+ .findOrCreateUser( function (sess, accessToken, accessSecret, twitUser) {
+ return usersByTwitId[twitUser.id] || (usersByTwitId[twitUser.id] = addUser('twitter', twitUser));
+ })
+/*.findOrCreateUser(function(session, accessToken, accessTokenSecret, twitterUserData) {*/
+/*var promise = this.Promise();*/
+/*users.findOrCreateByTwitterData(twitterUserData, accessToken, accessTokenSecret, promise);*/
+/*return promise;*/
+/*})*/
+ .redirectPath('/');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
- app.use(express.static(__dirname + '/public'));
- app.set('views', __dirname + '/views');
- app.set('view engine', 'jade');
+ app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: 'foobar' }));
- app.use(express.bodyParser());
+ app.use(everyauth.middleware());
app.use(express.methodOverride());
app.use(app.router);
- app.use(auth( [
- auth.Twitter({
- consumerKey: twitKey,
- consumerSecret: twitSec})
- ]) );
+ app.set('view engine', 'jade');
+ app.set('views', __dirname + '/views');
+ app.use(express.static(__dirname + '/public'));
+ everyauth.helpExpress(app);
});
app.configure('development', function(){
@@ -35,36 +64,18 @@ app.configure('production', function(){
app.use(express.errorHandler());
});
-// Connect Auth Protection Method
-function protect(req, res, next) {
- if( req.isAuthenticated() ){ next(); }
- else {
- req.authenticate(function(error, authenticated) {
- if( error ) next(new Error("Problem authenticating"));
- else {
- if( authenticated === true)next();
- else if( authenticated === false ) next(new Error("Access Denied!"));
- else {
- // Abort processing, browser interaction was required
- // (and has happened/is happening)
- }
- }
- })
- }
-}
// Routes
app.get('/', function(req, res){
- res.render('index', {
- title: 'Home'
- });
+ console.log("Got the index");
+ res.render('index', { title: 'Home' });
});
-app.get('/private', protect, function(req, res){
+app.get('/private', function(req, res){
+ console.log("Got the protected");
res.render('private', {title: 'Protected'});
});
-
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
View
2 package.json
@@ -5,6 +5,6 @@
, "dependencies": {
"express": "2.4.3"
, "jade": ">= 0.0.1"
- , "connect-auth": "0.4.1"
+ , "everyauth": "0.2.20"
}
}
View
19 views/layout.jade
@@ -7,14 +7,13 @@ html
a#Home(href="/") Home
br
a#Home(href="/private") Private
- ul#Authenticate
- li
- a(href="/sign_in") Sign In
- li or
- li
- a(href="/sign_up") Sign Up
- ul#Authed
- li Hi Abel!
- li
- a(href="/sign_out")
+ - if(everyauth.loggedIn)
+ ul#Authed
+ li Hi Abel!
+ li
+ a(href="/sign_out")
+ - else
+ ul#Authenticate
+ li
+ a(href="/auth/twitter") auth with twitter
!= body

0 comments on commit 032a2af

Please sign in to comment.