Skip to content

Commit

Permalink
Updated tests so they pass (still need to add more)
Browse files Browse the repository at this point in the history
Updated documentation #6
  • Loading branch information
mbell8903 committed Dec 3, 2015
1 parent c4201ca commit 5c9d3f6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
45 changes: 32 additions & 13 deletions README.md
Expand Up @@ -29,14 +29,30 @@ The strategy requires a `verify` callback, which is where the custom logic goes
`done` providing a user. Note that, req is always passed as the first parameter to the
`verify` callback.

Here is the pseudo code.

passport.use('strategy-name', new CustomStrategy(
function(req, callback) {
// Do your custom user finding logic here, or set to false based on req object
callback(null, user);
}
));
Here is the pseudo code:

```
passport.use('strategy-name', new CustomStrategy(
function(req, callback) {
// Do your custom user finding logic here, or set to false based on req object
callback(null, user);
}
));
```

And a basic example:

```
passport.use(new CustomStrategy(
function(req, done) {
User.findOne({
username: req.body.username
}, function (err, user) {
done(err, user);
});
}
));
```

#### Authenticate Requests

Expand All @@ -46,11 +62,14 @@ authenticate requests.
For example, as route middleware in an [Express](http://expressjs.com/)
application:

app.post('/login',
passport.authenticate('custom', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
});
```
app.post('/login',
passport.authenticate('custom', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
}
);
```

## Tests

Expand Down
6 changes: 4 additions & 2 deletions lib/strategy.js
Expand Up @@ -12,8 +12,10 @@ var passport = require('passport-strategy'),
*
* Examples:
* passport.use(new CustomStrategy(
* function(done) {
* User.findOne({ uid: 1 }, function (err, user) {
* function(req, done) {
* User.findOne({
* username: req.body.username
* }, function (err, user) {
* done(err, user);
* });
* }
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "passport-custom",
"version": "1.0.3",
"version": "1.0.4",
"description": "Custom authentication strategy for Passport.",
"keywords": [
"passport",
Expand Down
4 changes: 2 additions & 2 deletions test/strategy.error.test.js
Expand Up @@ -6,7 +6,7 @@ var chai = require('chai'),
describe('Strategy', function () {

describe('encountering an error during verification', function () {
var strategy = new Strategy(function (done) {
var strategy = new Strategy(function (req, done) {
done(new Error('something went wrong'));
});

Expand All @@ -31,7 +31,7 @@ describe('Strategy', function () {
});

describe('encountering an exception during verification', function () {
var strategy = new Strategy(function (done) {
var strategy = new Strategy(function (req, done) {
throw new Error('something went horribly wrong');
});

Expand Down
4 changes: 2 additions & 2 deletions test/strategy.fail.test.js
Expand Up @@ -7,7 +7,7 @@ var chai = require('chai'),
describe('Strategy', function () {

describe('failing authentication', function () {
var strategy = new Strategy(function (done) {
var strategy = new Strategy(function (req, done) {
return done(null, false);
});

Expand All @@ -31,7 +31,7 @@ describe('Strategy', function () {
});

describe('failing authentication with info', function () {
var strategy = new Strategy(function (done) {
var strategy = new Strategy(function (req, done) {
return done(null, false, { message: 'authentication failed' });
});

Expand Down
2 changes: 1 addition & 1 deletion test/strategy.normal.test.js
Expand Up @@ -7,7 +7,7 @@ var chai = require('chai'),
describe('Strategy', function () {

describe('handling a request with valid credentials in query', function () {
var strategy = new Strategy(function (done) {
var strategy = new Strategy(function (req, done) {
return done(null, { id: '1234' }, { scope: 'read' });
});

Expand Down

0 comments on commit 5c9d3f6

Please sign in to comment.