Skip to content

Commit

Permalink
add support for auth token in headers
Browse files Browse the repository at this point in the history
  • Loading branch information
adcentury committed Apr 10, 2019
1 parent 4e2026b commit 2ca9bc2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ coverage/
lib-cov/
coverage.json
npm-debug.log
package-lock.json
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function authenticate(options, verify) {
}

return function(socket, next) {
var token = socket.handshake.query.auth_token;
var token = socket.handshake.headers['x-auth-token'] || socket.handshake.query.auth_token;
var verified = function(err, user, message) {
if (err) {
return _this.fail(err, next);
Expand Down
25 changes: 24 additions & 1 deletion test/authenticate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,30 @@ describe('authenticate', function() {
expect(user.logged_in).to.be.true;
done();
});
})
});

it('should support auth token being passed in with extraHeaders', function(done) {
socket = io('http://localhost:9000', {
extraHeaders: {
'x-auth-token': data.valid_jwt.token
},
transportOptions: {
polling: {
extraHeaders: {
'x-auth-token': data.valid_jwt.token
}
}
},
'force new connection': true
});
socket.on('success', function(user) {
expect(user).to.be.an('object');
expect(user.name).to.equal(data.user.name);
expect(user.email).to.equal(data.user.email);
expect(user.logged_in).to.be.true;
done();
});
});
});

});

0 comments on commit 2ca9bc2

Please sign in to comment.