diff --git a/lib/client/auth-code.js b/lib/client/auth-code.js index 6accbce8..4fc7d206 100644 --- a/lib/client/auth-code.js +++ b/lib/client/auth-code.js @@ -42,7 +42,7 @@ module.exports = (config) => { * that represents the application privileges * @return {Promise} */ - async function getToken(params) { + async function getToken(params = {}) { const baseParams = { grant_type: 'authorization_code', }; diff --git a/lib/client/client.js b/lib/client/client.js index 700378d2..e29a8f4a 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -16,7 +16,7 @@ module.exports = (config) => { * that represents the application privileges * @return {Promise} */ - async function getToken(params) { + async function getToken(params = {}) { const baseParams = { grant_type: 'client_credentials', }; diff --git a/lib/client/password.js b/lib/client/password.js index 00756817..4f802bac 100644 --- a/lib/client/password.js +++ b/lib/client/password.js @@ -18,7 +18,7 @@ module.exports = (config) => { * that represents the application privileges * @return {Promise} */ - async function getToken(params) { + async function getToken(params = {}) { const baseParams = { grant_type: 'password', }; diff --git a/package-lock.json b/package-lock.json index 075b9c40..50d25b37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -487,9 +487,10 @@ "integrity": "sha512-O4QDrx+JoGKZc6aN64L04vqa7e41tIiLU+OvKdcYaEMP97UttL0f9GIi9/0A4WAMx0uBd6SidDIhktZhgOcN8Q==" }, "@hapi/boom": { - "version": "7.4.11", - "resolved": "https://registry.npmjs.org/@hapi/boom/-/boom-7.4.11.tgz", - "integrity": "sha512-VSU/Cnj1DXouukYxxkes4nNJonCnlogHvIff1v1RVoN4xzkKhMXX+GRmb3NyH1iar10I9WFPDv2JPwfH3GaV0A==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/@hapi/boom/-/boom-8.0.1.tgz", + "integrity": "sha512-SnBM2GzEYEA6AGFKXBqNLWXR3uNBui0bkmklYXX1gYtevVhDTy2uakwkSauxvIWMtlANGRhzChYg95If3FWCwA==", + "dev": true, "requires": { "@hapi/hoek": "8.x.x" } @@ -510,9 +511,9 @@ "integrity": "sha512-JPiBy+oSmsq3St7XlipfN5pNA6bDJ1kpa73PrK/zR29CVClDVqy04AanM/M/qx5bSF+I61DdCfAvRrujau+zRg==" }, "@hapi/joi": { - "version": "16.1.5", - "resolved": "https://registry.npmjs.org/@hapi/joi/-/joi-16.1.5.tgz", - "integrity": "sha512-FnVe0t1YQbF0H4fhFM6qBL7lIP4wdVHdFFBkloxgCkpKKdaCB6Z2UaNI0UalaDRHbRM9BvfTfyUKJg7tGtBSXg==", + "version": "16.1.7", + "resolved": "https://registry.npmjs.org/@hapi/joi/-/joi-16.1.7.tgz", + "integrity": "sha512-anaIgnZhNooG3LJLrTFzgGALTiO97zRA1UkvQHm9KxxoSiIzCozB3RCNCpDnfhTJD72QlrHA8nwGmNgpFFCIeg==", "requires": { "@hapi/address": "^2.1.2", "@hapi/formula": "^1.2.0", @@ -522,9 +523,9 @@ }, "dependencies": { "@hapi/hoek": { - "version": "8.2.5", - "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-8.2.5.tgz", - "integrity": "sha512-rmGFzok1zR3xZKd5m3ihWdqafXFxvPHoQ/78+AG5URKbEbJiwBBfRgzbu+07W5f3+07JRshw6QqGbVmCp8ntig==" + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-8.3.0.tgz", + "integrity": "sha512-C0QL9bmgUXTSuf8nDeGrpMjtJG7tPUr8wG6/wxPbP62tGwCwQtdMSJYfESowmY4P3Hn593f+8OzNY5bckcu/LQ==" } } }, @@ -534,9 +535,9 @@ "integrity": "sha512-dtXC/WkZBfC5vxscazuiJ6iq4j9oNx1SHknmIr8hofarpKUZKmlUVYVIhNVzIEgK5Wrc4GMHL5lZtt1uS2flmQ==" }, "@hapi/topo": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-3.1.4.tgz", - "integrity": "sha512-aVWQTOI9wBD6zawmOr6f+tdEIxQC8JXfQVLTjgGe8YEStAWGn/GNNVTobKJhbWKveQj2RyYF3oYbO9SC8/eOCA==", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-3.1.5.tgz", + "integrity": "sha512-bi9m1jrui9LlvtVdLaHv0DqeOoe+I8dep+nEcTgW6XxJHL3xArQcilYz3tIp0cRC4gWlsVtABK7vNKg4jzEmAA==", "requires": { "@hapi/hoek": "8.x.x" } @@ -549,6 +550,16 @@ "@hapi/boom": "7.x.x", "@hapi/bourne": "1.x.x", "@hapi/hoek": "8.x.x" + }, + "dependencies": { + "@hapi/boom": { + "version": "7.4.11", + "resolved": "https://registry.npmjs.org/@hapi/boom/-/boom-7.4.11.tgz", + "integrity": "sha512-VSU/Cnj1DXouukYxxkes4nNJonCnlogHvIff1v1RVoN4xzkKhMXX+GRmb3NyH1iar10I9WFPDv2JPwfH3GaV0A==", + "requires": { + "@hapi/hoek": "8.x.x" + } + } } }, "@nodelib/fs.scandir": { @@ -4117,9 +4128,9 @@ "dev": true }, "nock": { - "version": "11.3.5", - "resolved": "https://registry.npmjs.org/nock/-/nock-11.3.5.tgz", - "integrity": "sha512-6WGeZcWc3RExkBcMSYSrUm/5YukDo52m/jhwniQyrnuiCnKRljBwwje9vTwJyEi4J6m2bq0Aj6C1vzuM6iuaeg==", + "version": "11.3.6", + "resolved": "https://registry.npmjs.org/nock/-/nock-11.3.6.tgz", + "integrity": "sha512-54MSX4qeRnhwQQ2PSHlHc6pM6zNf7Dq9ni0BTFTurnDbUUssXl2Jy3E95ffaE8rZ/W/FWa9VSfzWDDnbdAsoTg==", "dev": true, "requires": { "chai": "^4.1.2", diff --git a/package.json b/package.json index 649028d7..1c3d05ab 100644 --- a/package.json +++ b/package.json @@ -44,13 +44,13 @@ "credentials" ], "dependencies": { - "@hapi/joi": "^16.1.5", + "@hapi/joi": "^16.1.7", "@hapi/wreck": "^15.1.0", "date-fns": "^2.4.1", "debug": "^4.1.1" }, "devDependencies": { - "@hapi/boom": "^7.4.11", + "@hapi/boom": "^8.0.1", "ava": "^2.4.0", "chance": "^1.1.0", "chance-access-token": "^1.0.1", @@ -59,7 +59,7 @@ "eslint-config-airbnb-base": "^14.0.0", "eslint-plugin-import": "^2.9.0", "lodash": "^4.17.15", - "nock": "^11.3.5", + "nock": "^11.3.6", "nyc": "^14.1.1" }, "license": "Apache-2.0" diff --git a/test/auth-code.js b/test/auth-code.js index 3ac2b737..df929090 100644 --- a/test/auth-code.js +++ b/test/auth-code.js @@ -396,6 +396,24 @@ test.serial('@getToken => resolves to an access token with a custom grant type', t.deepEqual(token, getAccessToken()); }); +test.serial('@getToken => resolves to an access token with no params', async (t) => { + const expectedRequestParams = { + grant_type: 'authorization_code', + }; + + const scopeOptions = getHeaderCredentialsScopeOptions(); + const server = createAuthorizationServer('https://authorization-server.org:443'); + const scope = server.tokenSuccess(scopeOptions, expectedRequestParams); + + const config = createModuleConfig(); + const oauth2 = oauth2Module.create(config); + + const token = await oauth2.authorizationCode.getToken(); + + scope.done(); + t.deepEqual(token, getAccessToken()); +}); + test.serial('@getToken => rejects the operation when a non json response is received', async (t) => { const expectedRequestParams = { grant_type: 'authorization_code', diff --git a/test/client.js b/test/client.js index 672d4e18..2714cc1b 100644 --- a/test/client.js +++ b/test/client.js @@ -235,6 +235,24 @@ test.serial('@getToken => resolves to an access token with a custom grant type', t.deepEqual(token, getAccessToken()); }); +test.serial('@getToken => resolves to an access token with no params', async (t) => { + const expectedRequestParams = { + grant_type: 'client_credentials', + }; + + const scopeOptions = getHeaderCredentialsScopeOptions(); + const server = createAuthorizationServer('https://authorization-server.org:443'); + const scope = server.tokenSuccess(scopeOptions, expectedRequestParams); + + const config = createModuleConfig(); + const oauth2 = oauth2Module.create(config); + + const token = await oauth2.clientCredentials.getToken(); + + scope.done(); + t.deepEqual(token, getAccessToken()); +}); + test.serial('@getToken => rejects the operation when a non json response is received', async (t) => { const expectedRequestParams = { grant_type: 'client_credentials', diff --git a/test/password.js b/test/password.js index e583f843..47f8cc09 100644 --- a/test/password.js +++ b/test/password.js @@ -254,6 +254,24 @@ test.serial('@getToken => resolves to an access token with a custom grant type', t.deepEqual(token, getAccessToken()); }); +test.serial('@getToken => resolves to an access token with no params', async (t) => { + const tokenRequestParams = { + grant_type: 'password', + }; + + const scopeOptions = getHeaderCredentialsScopeOptions(); + const server = createAuthorizationServer('https://authorization-server.org:443'); + const scope = server.tokenSuccess(scopeOptions, tokenRequestParams); + + const config = createModuleConfig(); + const oauth2 = oauth2Module.create(config); + + const token = await oauth2.ownerPassword.getToken(); + + scope.done(); + t.deepEqual(token, getAccessToken()); +}); + test.serial('@getToken => rejects the operation when a non json response is received', async (t) => { const tokenRequestParams = { grant_type: 'password',