From 94bad5cd36b70f828b2d5afee91f69338767b276 Mon Sep 17 00:00:00 2001 From: Chris Impey Date: Mon, 5 Oct 2015 17:52:43 +0100 Subject: [PATCH] Revert "change API_KEYS variable to be comma separated string as we're not using the JSON data at the mo and JSON causes issues in docker-compose.yml" This reverts commit c24d919c4e3a6046946b6e68d0ec7381cdb6ade1. --- Gruntfile.js | 2 +- lib/server.js | 2 +- lib/token_auth_strategy.js | 6 +++--- test/token_auth_strategy_tests.js | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 16c48b3..c4ae120 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -50,7 +50,7 @@ module.exports = function (grunt) { }, env: { test: { - API_KEYS: '12345' + API_KEYS: '{"12345": "test-user"}' } } }); diff --git a/lib/server.js b/lib/server.js index 1bd2769..1920314 100644 --- a/lib/server.js +++ b/lib/server.js @@ -21,7 +21,7 @@ const plugins = [ let authKeys; if (process.env.API_KEYS) { - authKeys = process.env.API_KEYS.split(','); + authKeys = JSON.parse(process.env.API_KEYS); } else { throw new Error('Environment variable API_KEYS not set'); } diff --git a/lib/token_auth_strategy.js b/lib/token_auth_strategy.js index 97493d8..7d52959 100644 --- a/lib/token_auth_strategy.js +++ b/lib/token_auth_strategy.js @@ -1,9 +1,9 @@ 'use strict'; -module.exports = function (keys) { +module.exports = function (keyData) { return (token, callback) => { - if (keys.indexOf(token) >= 0) { - return callback(null, true, {token}); + if (keyData[token]) { + return callback(null, true, {name: keyData[token], token}); } callback(null, false); diff --git a/test/token_auth_strategy_tests.js b/test/token_auth_strategy_tests.js index d6cd7d7..60ae6db 100644 --- a/test/token_auth_strategy_tests.js +++ b/test/token_auth_strategy_tests.js @@ -7,7 +7,7 @@ describe('token authenticator', () => { let authenticator; before(() => { - authenticator = authenticatorFactory('123456'); + authenticator = authenticatorFactory({123456: 'bigwednesday.io'}); }); it('returns true when token is found', () => { @@ -20,7 +20,7 @@ describe('token authenticator', () => { it('returns credentials when token is found', () => { authenticator('123456', (err, valid, credentials) => { expect(err).not.to.be.ok; - expect(credentials).to.deep.equal({token: '123456'}); + expect(credentials).to.deep.equal({name: 'bigwednesday.io', token: '123456'}); }); });