Skip to content

Pass additional info to Basic Strategy success callback #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Semgrep
on:
pull_request_target: {}
push:
branches: ["master"]
jobs:
semgrep:
name: Scan
runs-on: ubuntu-latest
if: (github.actor != 'dependabot[bot]' && github.actor != 'snyk-bot')
steps:
- uses: actions/checkout@v2
- uses: returntocorp/semgrep-action@v1
with:
publishToken: ${{ secrets.SEMGREP_APP_TOKEN }}
4 changes: 2 additions & 2 deletions lib/passport-http/strategies/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ BasicStrategy.prototype.authenticate = function(req) {

var self = this;

function verified(err, user) {
function verified(err, user, info) {
if (err) { return self.error(err); }
if (!user) { return self.fail(self._challenge()); }
self.success(user);
self.success(user, info);
}

if (self._passReqToCallback) {
Expand Down
5 changes: 5 additions & 0 deletions opslevel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
version: 1
repository:
owner: iam_federations
tags:
26 changes: 19 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"name": "passport-http",
"version": "0.3.0",
"version": "0.3.1",
"description": "HTTP Basic and Digest authentication strategies for Passport.",
"keywords": ["passport", "http", "basic", "digest", "auth", "authn", "authentication"],
"keywords": [
"passport",
"http",
"basic",
"digest",
"auth",
"authn",
"authentication"
],
"repository": {
"type": "git",
"url": "git://github.com/jaredhanson/passport-http.git"
Expand All @@ -15,10 +23,12 @@
"email": "[email protected]",
"url": "http://www.jaredhanson.net/"
},
"licenses": [ {
"type": "MIT",
"url": "http://www.opensource.org/licenses/MIT"
} ],
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/MIT"
}
],
"main": "./lib/passport-http",
"dependencies": {
"passport-strategy": "1.x.x"
Expand All @@ -29,5 +39,7 @@
"scripts": {
"test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js test/**/*-test.js"
},
"engines": { "node": ">= 0.4.0" }
"engines": {
"node": ">= 0.4.0"
}
}
42 changes: 42 additions & 0 deletions test/strategies/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,48 @@ vows.describe('BasicStrategy').addBatch({
},
},

'strategy that verifies a request with additional info': {
topic: function() {
var strategy = new BasicStrategy(function(userid, password, done) {
done(null, { username: userid, password: password }, { foo: 'bar' });
});
return strategy;
},

'after augmenting with actions': {
topic: function(strategy) {
var self = this;
var req = {};
strategy.success = function(user, info) {
self.callback(null, user, info);
}
strategy.fail = function() {
self.callback(new Error('should not be called'));
}
strategy.error = function() {
self.callback(new Error('should not be called'));
}

req.headers = {};
req.headers.authorization = 'Basic Ym9iOnNlY3JldA==';
process.nextTick(function () {
strategy.authenticate(req);
});
},

'should not generate an error' : function(err, user) {
assert.isNull(err);
},
'should authenticate' : function(err, user) {
assert.equal(user.username, 'bob');
assert.equal(user.password, 'secret');
},
'should authenticate with additional info' : function(err, user, info) {
assert.equal(info.foo, 'bar');
},
},
},

'strategy handling a request that is not verified': {
topic: function() {
var strategy = new BasicStrategy(function(userid, password, done) {
Expand Down