Comments (12)
Hey @JoshBarr, couldn't get https://github.com/sindresorhus/got#proxies to work?
I recognize the completeness of request, so rather than resolving to forks and duplicate packages I'll figure out a way to use other request libs.
from node-openid-client.
I think it shouldn't be that big of a deal as soon as we figure out a good interface. Your wrapper helps!
from node-openid-client.
https://github.com/panva/node-openid-client/tree/feature/swappable-request-client
Issuer.httpClient = {
get(url, options) {}, // return Promise
post(url, options) {}, // return Promise
HTTPError, // used error constructor
};
@JoshBarr opinion? I tried with your got-like request and got all tests to pass/
from node-openid-client.
that looks awesome, I like very much!
from node-openid-client.
@JoshBarr ^1.11.0
has landed, you can now plug request
instead of got
. Should you be moving forward with the fork please remove the certification notes from the README.
from node-openid-client.
thx josh, but can we have a proper exemple please?
this link not is not working
https://github.com/panva/node-openid-client/tree/feature/swappable-request-client
/opt/app-root/src/node_modules/got/index.js:229
--
| req.connection.once('connect', () => {
| ^
| TypeError: Cannot read property 'once' of null
| at EventEmitter.ee.once.req (/opt/app-root/src/node_modules/got/index.js:229:19)
| at EventEmitter.g (events.js:291:16)
| at emitOne (events.js:101:20)
| at EventEmitter.emit (events.js:188:7)
| at Immediate.setImmediate (/opt/app-root/src/node_modules/got/index.js:264:8)
| at runCallback (timers.js:637:20)
| at tryOnImmediate (timers.js:610:5)
| at processImmediate [as _immediateCallback] (timers.js:582:5)
from node-openid-client.
the feature branch results in the following being accepted
Issuer.httpClient = {
get(url, options) {}, // return Promise
post(url, options) {}, // return Promise
HTTPError, // used error constructor
};
What you fit those with is up to you. You may find the mapping of got to request in the original link @JoshBarr posted. This is definitely a more advanced topic so only get yourself on this path when necessary.
from node-openid-client.
@JoshBarr have you an exemple for using the wrapper, In the company we hace to use a proxy and got not working very well with proxy.
from node-openid-client.
@panva , its working, the wrapper of @JoshBarr is not working.
this exemple works well for me:
const request = require('request');
const HttpError = require('http-error-constructor');
/*
* url {String}
* options {Object}
* options.headers {Object}
* options.body {String|Object}
* options.query {Object}
* options.timeout {Number}
* options.retries {Number}
* options.followRedirect {Boolean}
*/
module.exports.get = function get(url, options) {
options.uri = url;
return new Promise((resolve, reject) => {
request.get(options, (error, response, body) => {
if(error) reject(err);
resolve(response);
});
});
};
module.exports.post = function post(url, options) {
options.uri = url;
delete options.from;
const body = options.body;
delete options.body;
options.form = body;
return new Promise((resolve, reject) => {
request.post(options, (error, response, body) => {
if(error) reject(err);
resolve(response);
});
});
};
module.exports.HTTPError = HttpError;
and added this in my app.js file, just before the issuer discover
const wrapper = require('./utils/wrapper');
Issuer.httpClient = wrapper;
and now the http_proxy works very well.
from node-openid-client.
The tests don't pass with your httpClient in, since this is a recurring topic let me see if i can accomodate a 100% working one myself.
from node-openid-client.
Here's a working request example that passes all tests.
'use strict';
const request = require('request');
const http = require('http');
class HTTPError extends Error {
constructor(response) {
let statusMessage;
if (response.statusMessage) {
statusMessage = response.statusMessage.replace(/\r?\n/g, ' ').trim();
} else {
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, options) {
if (options.form) {
options.form = options.body;
delete options.body;
}
return new Promise((resolve, reject) => {
request({
method,
url,
headers: options.headers,
qs: options.query,
body: options.body,
form: options.form,
followRedirect: options.followRedirect,
timeout: options.timeout,
}, (error, response, body) => {
if (error) {
reject(error);
} else {
response.body = body;
const statusCode = response.statusCode;
const limitStatusCode = options.followRedirect ? 299 : 399;
if (statusCode !== 304 && (statusCode < 200 || statusCode > limitStatusCode)) {
reject(new HTTPError(response));
return;
}
resolve(response);
}
});
});
}
/*
* url {String}
* options {Object}
* options.headers {Object}
* options.body {String|Object}
* options.form {Boolean}
* options.query {Object}
* options.timeout {Number}
* options.retries {Number}
* options.followRedirect {Boolean}
*/
module.exports.get = function get(url, options) {
return requestWrap('GET', url, options);
};
module.exports.post = function post(url, options) {
return requestWrap('POST', url, options);
};
module.exports.HTTPError = HTTPError;
from node-openid-client.
Calling for comments in #65
from node-openid-client.
Related Issues (20)
- Low-level errors during `Issuer.discover()` cause error without stack trace
- OAuth 2.0 Device Authorization Grant (Device Flow) - poll without PKCE HOT 3
- Type checking httpOptions and rejectUnauthorized
- RPError thrown when IdToken JWE Header enc is blank HOT 2
- client won't run under `edge` runtime HOT 1
- Support setting client_secret to an empty string when using client_secret_basic or client_secret_post HOT 1
- Cannot assign to read only property 'dpopProof' of object '#<Client>' HOT 2
- Unsuccessful Callback to Unknow client side error HOT 10
- isKeyObject check fails in Bun HOT 5
- Scope delimiter replace problem HOT 2
- Multiple authenticate requests from the same session causes state mismatch HOT 1
- Can't authenticate when the server advertises authorization_response_iss_parameter_supported HOT 2
- Requests made without Accept-Encoding header HOT 1
- "cty" should not be included in jwks query HOT 2
- URL is not a constructor at Issuer.request HOT 1
- Application and Identity manger on different domains HOT 1
- Support other status code than 200 HOT 4
- Unable to use private_key_jwt auth method with Azure.
- Audience matching doesn't work as intended HOT 1
- Using `authorizationUrl()` in combination with PAR adds too many parameters HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-openid-client.