Skip to content

Commit 5d7b3cb

Browse files
committed
Add missing response to authentication handler
1 parent 9968589 commit 5d7b3cb

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ ExpressOAuthServer.prototype.authenticate = function() {
3737

3838
return function(req, res, next) {
3939
var request = new Request(req);
40+
var response = new Response(res);
4041

4142
return Promise.bind(this)
4243
.then(function() {
43-
return server.authenticate(request);
44+
return server.authenticate(request, response);
4445
})
4546
.tap(function(token) {
4647
req.app.locals.oauth = { token: token };

test/integration/index_test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ describe('ExpressOAuthServer', function() {
5555
.expect({ error: 'invalid_argument', error_description: 'Invalid argument: model does not implement `getAccessToken()`' })
5656
.end(done);
5757
});
58+
59+
it('should authenticate the request', function(done) {
60+
var token = { user: {} };
61+
var model = {
62+
getAccessToken: function() {
63+
return token;
64+
}
65+
};
66+
var oauth = new ExpressOAuthServer({ model: model });
67+
68+
app.use(oauth.authenticate());
69+
70+
app.use(function(req, res, next) {
71+
res.send();
72+
73+
next();
74+
});
75+
76+
request(app.listen())
77+
.get('/')
78+
.set('Authorization', 'Bearer foobar')
79+
.expect(200)
80+
.end(done);
81+
});
5882
});
5983

6084
describe('authorize()', function() {

test/unit/index_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ describe('ExpressOAuthServer', function() {
3333
.get('/')
3434
.end(function() {
3535
oauth.server.authenticate.callCount.should.equal(1);
36-
oauth.server.authenticate.firstCall.args.should.have.length(1);
36+
oauth.server.authenticate.firstCall.args.should.have.length(2);
3737
oauth.server.authenticate.firstCall.args[0].should.be.an.instanceOf(Request);
38+
oauth.server.authenticate.firstCall.args[1].should.be.an.instanceOf(Response);
3839
oauth.server.authenticate.restore();
3940

4041
done();

0 commit comments

Comments
 (0)