Skip to content

Commit

Permalink
fix: regression from #272
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Jun 26, 2020
1 parent 806eac9 commit 9bff960
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/client.js
Expand Up @@ -1594,10 +1594,11 @@ BaseClient.prototype.resource = deprecate(
/* istanbul ignore next */
async function resource(resourceUrl, accessToken, options) {
let token = accessToken;
const opts = defaultsDeep({}, options, {
const opts = {
verb: 'GET',
via: 'header',
});
...options,
};

if (token instanceof TokenSet) {
if (!token.access_token) {
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/client.js
Expand Up @@ -5,7 +5,7 @@ const { random } = require('./generators');
const now = require('./unix_timestamp');
const request = require('./request');
const instance = require('./weak_cache');
const { deep: defaultsDeep } = require('./defaults');
const merge = require('./merge');

const formUrlEncode = (value) => encodeURIComponent(value).replace(/%20/g, '+');

Expand Down Expand Up @@ -125,7 +125,7 @@ async function authenticatedPost(endpoint, opts, {
clientAssertionPayload, endpointAuthMethod = endpoint,
} = {}) {
const auth = await authFor.call(this, endpointAuthMethod, { clientAssertionPayload });
const requestOpts = defaultsDeep({ form: true }, auth, opts);
const requestOpts = merge(opts, auth, { form: true });

const mTLS = this[`${endpointAuthMethod}_endpoint_auth_method`].includes('tls_client_auth')
|| (endpoint === 'token' && this.tls_client_certificate_bound_access_tokens);
Expand Down
23 changes: 23 additions & 0 deletions lib/helpers/merge.js
@@ -0,0 +1,23 @@
/* eslint-disable no-restricted-syntax */

const isPlainObject = require('./is_plain_object');

function merge(...sources) {
const target = {};
for (const source of sources) {
if (!isPlainObject(source)) {
continue; // eslint-disable-line no-continue
}
for (const [key, value] of Object.entries(source)) {
if (isPlainObject(target[key]) && isPlainObject(value)) {
target[key] = merge(target[key], value);
} else if (typeof value !== 'undefined') {
target[key] = value;
}
}
}

return target;
}

module.exports = merge.bind(undefined, false);

0 comments on commit 9bff960

Please sign in to comment.