Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to omit params on all token exchange methods (omit) #268

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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