Skip to content

Commit

Permalink
Expose auth mode in request.auth.mode. Closes #1790
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Jul 16, 2014
1 parent e3c044f commit a393307
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ internals.Auth.prototype._routeConfig = function (request) {
internals.Auth.authenticate = function (request, next) {

var auth = request.server.auth;
var config = auth._routeConfig(request);
if (!config) {
return next();
}

return auth._authenticate(request, next);
};

Expand All @@ -158,6 +153,11 @@ internals.Auth.prototype._authenticate = function (request, next) {
var self = this;

var config = this._routeConfig(request);
if (!config) {
return next();
}

request.auth.mode = config.mode;

var authErrors = [];
var strategyPos = 0;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hapi",
"description": "HTTP Server framework",
"homepage": "http://hapijs.com",
"version": "6.1.0",
"version": "6.2.0",
"repository": {
"type": "git",
"url": "git://github.com/spumko/hapi"
Expand Down
15 changes: 15 additions & 0 deletions test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ describe('Auth', function () {
});
});

it('exposes mode', function (done) {

var server = new Hapi.Server();
server.auth.scheme('custom', internals.implementation);
server.auth.strategy('default', 'custom', true, { users: { steve: {} } });
server.route({ method: 'GET', path: '/', handler: function (request, reply) { reply(request.auth.mode); } });

server.inject({ url: '/', headers: { authorization: 'Custom steve' } }, function (res) {

expect(res.statusCode).to.equal(200);
expect(res.result).to.equal('required');
done();
});
});

it('sets default', function (done) {

var server = new Hapi.Server();
Expand Down

0 comments on commit a393307

Please sign in to comment.