diff --git a/docs/README.md b/docs/README.md index e4e2e1752..0eab90408 100644 --- a/docs/README.md +++ b/docs/README.md @@ -519,19 +519,10 @@ property. ## HTTP Request Library / Proxy settings -By default oidc-provider uses the [got][got-library] module. Because of its lightweight nature of +oidc-provider uses the [got][got-library] module. Because of its lightweight nature of the provider will not use environment-defined http(s) proxies. In order to have them used you'll -need to require and tell oidc-provider to use [request][request-library] instead. - -```sh -# add request to your application package bundle -npm install request@^2.0.0 --save -``` - -```js -// tell oidc-provider to use request instead of got -Provider.useRequest(); -``` +need to follow got's [README](https://github.com/sindresorhus/got#proxies) and use e.g. +[`global-tunnel`](https://github.com/np-maintain/global-tunnel) ## Changing HTTP Request Defaults diff --git a/lib/helpers/http/index.js b/lib/helpers/http/index.js index e4256a618..c12669a29 100644 --- a/lib/helpers/http/index.js +++ b/lib/helpers/http/index.js @@ -7,11 +7,6 @@ const httpWrapper = { this.get = got.get; this.post = got.post; }, - useRequest() { - const request = require('./request'); // eslint-disable-line global-require - this.get = request.get; - this.post = request.post; - }, }; module.exports = httpWrapper; diff --git a/lib/helpers/http/request.js b/lib/helpers/http/request.js deleted file mode 100644 index e982c2954..000000000 --- a/lib/helpers/http/request.js +++ /dev/null @@ -1,77 +0,0 @@ -/* istanbul ignore file */ - -const http = require('http'); - -const request = require('request'); // eslint-disable-line import/no-unresolved, import/no-extraneous-dependencies - -/* - * url {String} - * options {Object} - * options.headers {Object} - * options.body {String|Object} - * options.form {Boolean} - * options.query {Object} - * options.timeout {Number} - * options.retry {Number} - * options.followRedirect {Boolean} - */ - -class HTTPError extends Error { - constructor(response) { - const statusMessage = http.STATUS_CODES[response.statusCode]; - super(`Response code ${response.statusCode} (${statusMessage})`, {}); - this.name = 'HTTPError'; - this.statusCode = response.statusCode; - this.statusMessage = statusMessage; - this.headers = response.headers; - this.response = response; - } -} - -function requestWrap(method, url, { - form, - body, - query, - ...options -}) { - if (form) { - /* eslint-disable no-param-reassign */ - form = body; - body = undefined; - /* eslint-enable no-param-reassign */ - } - return new Promise((resolve, reject) => { - request({ - ...options, - body, - form, - method, - url, - qs: query, - }, (error, response, responseBody) => { - if (error) { - reject(error); - } else { - response.body = responseBody; - const { statusCode } = response; - const limitStatusCode = options.followRedirect ? 299 : 399; - - if (statusCode !== 304 && (statusCode < 200 || statusCode > limitStatusCode)) { - reject(new HTTPError(response)); - return; - } - - resolve(response); - } - }); - }); -} - -module.exports = { - get: function requestGet(url, options) { - return requestWrap('GET', url, options); - }, - post: function requestPost(url, options) { - return requestWrap('POST', url, options); - }, -}; diff --git a/lib/provider.js b/lib/provider.js index ebf60ca5e..2b28ed655 100644 --- a/lib/provider.js +++ b/lib/provider.js @@ -353,17 +353,9 @@ class Provider extends events.EventEmitter { get DeviceCode() { return instance(this).DeviceCode; } get requestUriCache() { return instance(this).requestUriCache; } - - static useGot() { // eslint-disable-line class-methods-use-this - httpWrapper.useGot(); - } - - static useRequest() { // eslint-disable-line class-methods-use-this - /* istanbul ignore next */ - httpWrapper.useRequest(); - } } -Provider.useGot(); + +httpWrapper.useGot(); ['env', 'proxy', 'subdomainOffset', 'keys'].forEach((method) => { Object.defineProperty(Provider.prototype, method, {