diff --git a/README.md b/README.md index 368ae03..a86bd63 100644 --- a/README.md +++ b/README.md @@ -108,9 +108,17 @@ For more validation options see [auth0/jsonwebtoken](https://github.com/auth0/no Append the jwt token using query string: ```javascript +//// token part of query string //// var socket = io.connect('http://localhost:9000', { 'query': 'token=' + your_jwt }); + + +//// token coming in as Authorization Header //// +var socket = io.connect('http://localhost:9000', { + 'extraHeaders': { Authorization: `Bearer ${your_jwt}` } +}); + ``` Append the jwt token using 'Authorization Header' (Bearer Token): diff --git a/test/authorizer.test.js b/test/authorizer.test.js index 3e2efc3..654c0ae 100644 --- a/test/authorizer.test.js +++ b/test/authorizer.test.js @@ -27,7 +27,7 @@ describe('authorizer', function () { describe('when the user is logged in', function() { - beforeEach(function (done) { + before(function (done) { request.post({ url: 'http://localhost:9000/login', form: { username: 'jose', password: 'Pa123' }, @@ -38,6 +38,17 @@ describe('authorizer', function () { }.bind(this)); }); + it('auth headers are supported', function (done){ + var socket = io.connect('http://localhost:9000', { + 'forceNew':true, + 'extraHeaders': {'Authorization': `Bearer ${this.token}`} + }); + socket.on('connect', function(){ + socket.close(); + done(); + }).on('error', done); + }); + it('should do the handshake and connect', function (done){ var socket = io.connect('http://localhost:9000', { 'forceNew':true,