diff --git a/src/oauth.js b/src/oauth.js index 2279c08..863ad23 100644 --- a/src/oauth.js +++ b/src/oauth.js @@ -5,9 +5,10 @@ export function oauth (axios, { url, ...credentials }) { ...moreCredentials } - // remove blank scope - if ('scope' in body && !body.scope) { - delete body.scope + // remove all blank values + for (const key of Object.keys(body)) { + if (!body[key]) + delete body[key] } return axios({ diff --git a/src/oauth.test.js b/src/oauth.test.js index b76e4ca..ddbcb26 100644 --- a/src/oauth.test.js +++ b/src/oauth.test.js @@ -70,6 +70,26 @@ describe('oauth()', function () { }) }) + test('should omit any null or undefined value', async function () { + const params = { + url: 'https://oauth.com/2.0/token', + grant_type: 'client_credentials', + client_id: undefined, + client_secret: undefined, + scope: null + } + + const actualConfig = {} + const auth = oauth(fakeAxios(actualConfig), params) + await auth() + + assert.deepStrictEqual(actualConfig, { + url: 'https://oauth.com/2.0/token', + method: 'post', + data: 'grant_type=client_credentials' + }) + }) + test('should resolve to the OAuth token response', async function () { const expectedData = { access_token: 'FAKE_TOKEN', expires_in: 5 } const auth = oauth(fakeAxios({}, expectedData), {})