Skip to content

Commit 9502d99

Browse files
author
Daniel Harvey
committed
Bring fork up to date
Merge branch 'master' of https://github.com/danielsharvey/passport into passport-doco-updates.
2 parents 4c3dbec + be92845 commit 9502d99

File tree

17 files changed

+118
-179
lines changed

17 files changed

+118
-179
lines changed

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
build/
1+
docs/
22
reports/
33

4-
# Node.js
5-
node_modules/
6-
npm-debug.log
7-
84
# Mac OS X
95
.DS_Store
6+
7+
# Node.js
8+
node_modules
9+
npm-debug.log

.npmignore

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
Makefile
2-
README.md
3-
build/
42
docs/
53
examples/
64
reports/
7-
support/
85
test/
96

10-
# Node.js
11-
.npmignore
12-
node_modules/
13-
npm-debug.log
14-
15-
# Mac OS X
16-
.DS_Store
17-
18-
# Git
19-
.git*
20-
21-
# Utilities
227
.jshintrc
238
.travis.yml

.travis.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
language: "node_js"
22
node_js:
3+
- "5"
4+
- "4"
5+
- "3" # io.js
6+
- "2" # io.js
7+
- "1" # io.js
38
- "0.12"
49
- "0.10"
5-
- "iojs"
10+
- "0.8"
11+
- "0.6"
12+
613

714
before_install:
8-
- "npm install istanbul -g"
9-
- "npm install coveralls -g"
15+
- "npm install [email protected] -g"
16+
- "preinstall-compat"
1017

11-
script: "make ci-travis"
18+
script:
19+
- "make test-cov"
1220

1321
after_success:
14-
- "make submit-cov-to-coveralls"
22+
- "make report-cov"
23+
24+
sudo: false

Makefile

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,25 @@
1-
SOURCES ?= lib/*.js lib/**/*.js
2-
TESTS ?= test/*.test.js test/**/*.test.js
1+
include node_modules/make-node/main.mk
32

4-
test: test-mocha
5-
test-cov: test-istanbul-mocha
6-
view-cov: view-istanbul-report
7-
lint: lint-jshint
8-
lint-tests: lint-tests-jshint
93

4+
SOURCES = lib/*.js lib/**/*.js
5+
TESTS = test/*.test.js test/**/*.test.js
106

11-
# ==============================================================================
12-
# Node.js
13-
# ==============================================================================
14-
include support/mk/node.mk
15-
include support/mk/mocha.mk
16-
include support/mk/istanbul.mk
7+
LCOVFILE = ./reports/coverage/lcov.info
178

18-
# ==============================================================================
19-
# Analysis
20-
# ==============================================================================
21-
include support/mk/notes.mk
22-
include support/mk/jshint.mk
9+
MOCHAFLAGS = --require ./test/bootstrap/node
2310

24-
# ==============================================================================
25-
# Reports
26-
# ==============================================================================
27-
include support/mk/coveralls.mk
2811

29-
# ==============================================================================
30-
# Continuous Integration
31-
# ==============================================================================
32-
submit-cov-to-coveralls: submit-istanbul-lcov-to-coveralls
12+
view-docs:
13+
open ./docs/index.html
3314

34-
# Travis CI
35-
ci-travis: test test-cov
15+
view-cov:
16+
open ./reports/coverage/lcov-report/index.html
3617

37-
# ==============================================================================
38-
# Clean
39-
# ==============================================================================
40-
clean:
41-
rm -rf build
42-
rm -rf reports
18+
clean: clean-docs clean-cov
19+
-rm -r $(REPORTSDIR)
4320

44-
clobber: clean clobber-node
21+
clobber: clean
22+
-rm -r node_modules
4523

4624

47-
.PHONY: test test-cov view-cov lint lint-tests submit-cov-to-coveralls ci-travis clean clobber
25+
.PHONY: clean clobber

README.md

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ hooks for controlling what occurs when authentication succeeds or fails.
2121

2222
## Install
2323

24-
$ npm install passport
24+
```
25+
$ npm install passport
26+
```
2527

2628
## Usage
2729

@@ -35,16 +37,18 @@ or [Twitter](http://twitter.com/)), or federated authentication using [OpenID](h
3537
Before authenticating requests, the strategy (or strategies) used by an
3638
application must be configured.
3739

38-
passport.use(new LocalStrategy(
39-
function(username, password, done) {
40-
User.findOne({ username: username }, function (err, user) {
41-
if (err) { return done(err); }
42-
if (!user) { return done(null, false); }
43-
if (!user.verifyPassword(password)) { return done(null, false); }
44-
return done(null, user);
45-
});
46-
}
47-
));
40+
```javascript
41+
passport.use(new LocalStrategy(
42+
function(username, password, done) {
43+
User.findOne({ username: username }, function (err, user) {
44+
if (err) { return done(err); }
45+
if (!user) { return done(null, false); }
46+
if (!user.verifyPassword(password)) { return done(null, false); }
47+
return done(null, user);
48+
});
49+
}
50+
));
51+
```
4852

4953
There are 300+ strategies. Find the ones you want at: [passportjs.org](http://passportjs.org)
5054

@@ -60,15 +64,17 @@ serialization and deserialization logic. In a typical application, this will be
6064
as simple as serializing the user ID, and finding the user by ID when
6165
deserializing.
6266

63-
passport.serializeUser(function(user, done) {
64-
done(null, user.id);
65-
});
67+
```javascript
68+
passport.serializeUser(function(user, done) {
69+
done(null, user.id);
70+
});
6671

67-
passport.deserializeUser(function(id, done) {
68-
User.findById(id, function (err, user) {
69-
done(err, user);
70-
});
71-
});
72+
passport.deserializeUser(function(id, done) {
73+
User.findById(id, function (err, user) {
74+
done(err, user);
75+
});
76+
});
77+
```
7278

7379
#### Middleware
7480

@@ -78,24 +84,28 @@ with the required `passport.initialize()` middleware. If your application uses
7884
persistent login sessions (recommended, but not required), `passport.session()`
7985
middleware must also be used.
8086

81-
var app = express();
82-
app.use(require('serve-static')(__dirname + '/../../public'));
83-
app.use(require('cookie-parser')());
84-
app.use(require('body-parser').urlencoded({ extended: true }));
85-
app.use(require('express-session')({ secret: 'keyboard cat', resave: true, saveUninitialized: true }));
86-
app.use(passport.initialize());
87-
app.use(passport.session());
87+
```javascript
88+
var app = express();
89+
app.use(require('serve-static')(__dirname + '/../../public'));
90+
app.use(require('cookie-parser')());
91+
app.use(require('body-parser').urlencoded({ extended: true }));
92+
app.use(require('express-session')({ secret: 'keyboard cat', resave: true, saveUninitialized: true }));
93+
app.use(passport.initialize());
94+
app.use(passport.session());
95+
```
8896

8997
#### Authenticate Requests
9098

9199
Passport provides an `authenticate()` function, which is used as route
92100
middleware to authenticate requests.
93101

94-
app.post('/login',
95-
passport.authenticate('local', { failureRedirect: '/login' }),
96-
function(req, res) {
97-
res.redirect('/');
98-
});
102+
```javascript
103+
app.post('/login',
104+
passport.authenticate('local', { failureRedirect: '/login' }),
105+
function(req, res) {
106+
res.redirect('/');
107+
});
108+
```
99109

100110
## Strategies
101111

@@ -122,10 +132,12 @@ The following table lists commonly used strategies:
122132

123133
- For a complete, working example, refer to the [example](https://github.com/passport/express-4.x-local-example)
124134
that uses [passport-local](https://github.com/jaredhanson/passport-local).
125-
- **Local Strategy**: Refer to the following tutorials for setting up user authentication via LocalStrategy (`passport-local`)
135+
- **Local Strategy**: Refer to the following tutorials for setting up user authentication via LocalStrategy (`passport-local`):
126136
- Express v3x - [Tutorial](http://mherman.org/blog/2013/11/11/user-authentication-with-passport-dot-js/) / [working example](https://github.com/mjhea0/passport-local)
127137
- Express v4x - [Tutorial](http://mherman.org/blog/2015/01/31/local-authentication-with-passport-and-express-4/) / [working example](https://github.com/mjhea0/passport-local-express4)
128-
- **Social Authentication**: Refer to this [tutorial](http://mherman.org/blog/2013/11/10/social-authentication-with-passport-dot-js/) for setting up various social authentication strategies, including a working example found on this [repo](https://github.com/mjhea0/passport-examples).
138+
- **Social Authentication**: Refer to the following tutorials for setting up various social authentication strategies:
139+
- Express v3x - [Tutorial](http://mherman.org/blog/2013/11/10/social-authentication-with-passport-dot-js/) / [working example](https://github.com/mjhea0/passport-examples)
140+
- Express v4x - [Tutorial](http://mherman.org/blog/2015/09/26/social-authentication-in-node-dot-js-with-passport) / [working example](https://github.com/mjhea0/passport-social-auth)
129141

130142
## Related Modules
131143

@@ -140,8 +152,10 @@ that build upon or integrate with Passport.
140152

141153
## Tests
142154

143-
$ npm install
144-
$ make test
155+
```
156+
$ npm install
157+
$ make test
158+
```
145159

146160
## Credits
147161

lib/errors/authenticationerror.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* `AuthenticationError` error.
33
*
4+
* @constructor
45
* @api private
56
*/
67
function AuthenticationError(message, status) {
@@ -11,13 +12,9 @@ function AuthenticationError(message, status) {
1112
this.status = status || 401;
1213
}
1314

14-
/**
15-
* Inherit from `Error`.
16-
*/
15+
// Inherit from `Error`.
1716
AuthenticationError.prototype.__proto__ = Error.prototype;
1817

1918

20-
/**
21-
* Expose `AuthenticationError`.
22-
*/
19+
// Expose constructor.
2320
module.exports = AuthenticationError;

lib/framework/connect.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,25 @@ var initialize = require('../middleware/initialize')
1515
* @return {Object}
1616
* @api protected
1717
*/
18-
module.exports = function() {
18+
exports = module.exports = function() {
1919

2020
// HTTP extensions.
21-
require('../http/request');
21+
exports.__monkeypatchNode();
2222

2323
return {
2424
initialize: initialize,
2525
authenticate: authenticate
2626
};
2727
};
28+
29+
exports.__monkeypatchNode = function() {
30+
var http = require('http');
31+
var IncomingMessageExt = require('../http/request');
32+
33+
http.IncomingMessage.prototype.login =
34+
http.IncomingMessage.prototype.logIn = IncomingMessageExt.logIn;
35+
http.IncomingMessage.prototype.logout =
36+
http.IncomingMessage.prototype.logOut = IncomingMessageExt.logOut;
37+
http.IncomingMessage.prototype.isAuthenticated = IncomingMessageExt.isAuthenticated;
38+
http.IncomingMessage.prototype.isUnauthenticated = IncomingMessageExt.isUnauthenticated;
39+
};

lib/http/request.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/**
22
* Module dependencies.
33
*/
4-
var http = require('http')
5-
, req = http.IncomingMessage.prototype;
4+
//var http = require('http')
5+
// , req = http.IncomingMessage.prototype;
66

77

8+
var req = exports = module.exports = {};
9+
810
/**
9-
* Intiate a login session for `user`.
11+
* Initiate a login session for `user`.
1012
*
1113
* Options:
1214
* - `session` Save login state in session, defaults to _true_

lib/middleware/authenticate.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Module dependencies.
33
*/
44
var http = require('http')
5+
, IncomingMessageExt = require('../http/request')
56
, AuthenticationError = require('../errors/authenticationerror');
67

78

@@ -30,7 +31,7 @@ var http = require('http')
3031
* message for failures (overrides any from the strategy itself).
3132
* - `assignProperty` Assign the object provided by the verify callback to given property
3233
*
33-
* An optional `callback` can be supplied to allow the application to overrride
34+
* An optional `callback` can be supplied to allow the application to override
3435
* the default manner in which authentication attempts are handled. The
3536
* callback has the following signature, where `user` will be set to the
3637
* authenticated user on a successful authentication attempt, or `false`
@@ -91,6 +92,12 @@ module.exports = function authenticate(passport, name, options, callback) {
9192
}
9293

9394
return function authenticate(req, res, next) {
95+
if (http.IncomingMessage.prototype.logIn
96+
&& http.IncomingMessage.prototype.logIn !== IncomingMessageExt.logIn) {
97+
require('../framework/connect').__monkeypatchNode();
98+
}
99+
100+
94101
// accumulator for failures from each strategy in the chain
95102
var failures = [];
96103

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "passport",
3-
"version": "0.3.0",
3+
"version": "0.3.2",
44
"description": "Simple, unobtrusive authentication for Node.js.",
55
"keywords": [
66
"express",
@@ -26,7 +26,7 @@
2626
"licenses": [
2727
{
2828
"type": "MIT",
29-
"url": "http://www.opensource.org/licenses/MIT"
29+
"url": "http://opensource.org/licenses/MIT"
3030
}
3131
],
3232
"main": "./lib",
@@ -35,6 +35,7 @@
3535
"pause": "0.0.1"
3636
},
3737
"devDependencies": {
38+
"make-node": "0.3.x",
3839
"mocha": "2.x.x",
3940
"chai": "2.x.x",
4041
"chai-connect-middleware": "0.3.x",
@@ -47,4 +48,4 @@
4748
"scripts": {
4849
"test": "node_modules/.bin/mocha --reporter spec --require test/bootstrap/node test/*.test.js test/**/*.test.js"
4950
}
50-
}
51+
}

0 commit comments

Comments
 (0)