Skip to content

Commit

Permalink
Merge pull request #268 from lelylan/feature/support-default-params
Browse files Browse the repository at this point in the history
Add support to omit params on all token exchange methods (omit)
  • Loading branch information
jonathansamines authored Oct 7, 2019
2 parents bd4da5c + 96c6cd7 commit 2d2d326
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/client/auth-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand Down
2 changes: 1 addition & 1 deletion lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand Down
2 changes: 1 addition & 1 deletion lib/client/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand Down
41 changes: 26 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions test/auth-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 18 additions & 0 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 18 additions & 0 deletions test/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 2d2d326

Please sign in to comment.