-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit. attempting to use connect-auth...but it doesn't appea…
…r to be working
- Loading branch information
0 parents
commit 664c1d3
Showing
7 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.DS_Store | ||
*.swp | ||
*.swo | ||
node_modules | ||
conf |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var express = require('express'), | ||
auth = require('connect-auth'), | ||
twitKey = "809JiWRofheAvdYgO4ACA", | ||
twitSec = "tNe4jr0aCiPRe52QVsVY1IJsZKcesf3ORyabmfQ6Ms"; | ||
|
||
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.cookieParser()); | ||
app.use(express.session({ secret: 'foobar' })); | ||
app.use(express.bodyParser()); | ||
app.use(express.methodOverride()); | ||
app.use(app.router); | ||
app.use(auth( [ | ||
auth.Twitter({ | ||
consumerKey: twitKey, | ||
consumerSecret: twitSec}) | ||
]) ); | ||
}); | ||
|
||
app.configure('development', function(){ | ||
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | ||
}); | ||
|
||
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' | ||
}); | ||
}); | ||
|
||
app.get('/private', protect, function(req, res){ | ||
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); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "application-name" | ||
, "version": "0.0.1" | ||
, "private": true | ||
, "dependencies": { | ||
"express": "2.4.3" | ||
, "jade": ">= 0.0.1" | ||
, "connect-auth": "0.4.1" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
body { | ||
padding: 50px; | ||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; | ||
} | ||
|
||
a { | ||
color: #00B7FF; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
h1= title | ||
p Welcome to #{title} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
!!! | ||
html | ||
head | ||
title Auth App: #{title} | ||
link(rel='stylesheet', href='/stylesheets/style.css') | ||
body | ||
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") | ||
!= body |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
h1 THIS IS A PRIVATE PAGE | ||
p This page should require a login. |