Skip to content

Commit

Permalink
refactor: remove deprecated client.resource()
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the deprecated `client.resource()` method was removed
  • Loading branch information
panva committed Sep 8, 2020
1 parent ba56b29 commit c0ec865
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 74 deletions.
70 changes: 1 addition & 69 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-classes-per-file */

const { inspect, deprecate } = require('util');
const { inspect } = require('util');
const stdhttp = require('http');
const crypto = require('crypto');
const { strict: assert } = require('assert');
Expand Down Expand Up @@ -30,8 +30,6 @@ const instance = require('./helpers/weak_cache');
const { authenticatedPost, resolveResponseType, resolveRedirectUri } = require('./helpers/client');
const DeviceFlowHandle = require('./device_flow_handle');

const { deep: defaultsDeep } = defaults;

function pickCb(input) {
return pick(input, ...CALLBACK_PROPERTIES);
}
Expand Down Expand Up @@ -1589,70 +1587,4 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
}
};

// TODO: remove in 4.x
BaseClient.prototype.resource = deprecate(
/* istanbul ignore next */
async function resource(resourceUrl, accessToken, options) {
let token = accessToken;
const opts = {
verb: 'GET',
via: 'header',
...options,
};

if (token instanceof TokenSet) {
if (!token.access_token) {
throw new TypeError('access_token not present in TokenSet');
}
opts.tokenType = opts.tokenType || token.token_type;
token = token.access_token;
}

const verb = String(opts.verb).toUpperCase();
let requestOpts;

switch (opts.via) {
case 'query':
if (verb !== 'GET') {
throw new TypeError('resource servers should only parse query strings for GET requests');
}
requestOpts = { query: { access_token: token } };
break;
case 'body':
if (verb !== 'POST') {
throw new TypeError('can only send body on POST');
}
requestOpts = { form: true, body: { access_token: token } };
break;
default:
requestOpts = {
headers: {
Authorization: authorizationHeaderValue(token, opts.tokenType),
},
};
}

if (opts.params) {
if (verb === 'POST') {
defaultsDeep(requestOpts, { body: opts.params });
} else {
defaultsDeep(requestOpts, { query: opts.params });
}
}

if (opts.headers) {
defaultsDeep(requestOpts, { headers: opts.headers });
}

const mTLS = !!this.tls_client_certificate_bound_access_tokens;

return request.call(this, {
...requestOpts,
encoding: null,
method: verb,
url: resourceUrl,
}, { mTLS });
}, 'client.resource() is deprecated, use client.requestResource() instead, see docs for API details',
);

module.exports.BaseClient = BaseClient;
5 changes: 0 additions & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,6 @@ export class Client {
*/
userinfo(accessToken: TokenSet | string, options?: { verb?: 'GET' | 'POST', via?: 'header' | 'body' | 'query', tokenType?: string, params?: object }): Promise<UserinfoResponse>;

/**
* @deprecated in favor of client.requestResource
*/
resource(resourceUrl: string, accessToken: TokenSet | string, options?: { headers?: object, verb?: 'GET' | 'POST', via?: 'header' | 'body' | 'query', tokenType?: string }): GotPromise<Buffer>;

/**
* Fetches an arbitrary resource with the provided Access Token in an Authorization header.
*
Expand Down

0 comments on commit c0ec865

Please sign in to comment.