diff --git a/docs/README.md b/docs/README.md index fb192296..c99790ce 100644 --- a/docs/README.md +++ b/docs/README.md @@ -538,8 +538,7 @@ you need to work around, e.g. adding custom headers or body payload parameters. const { custom } = require('openid-client'); client[custom.http_options] = function (options) { // see https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options - // key, cert, ca, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder, passphrase - // pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, sessionIdContext + // key, cert, ca, rejectUnauthorized options.cert = cert; // | | | options.key = key; // | | | | // custom CA @@ -572,15 +571,6 @@ client[custom.http_options] = function (options) { // https://github.com/sindresorhus/got/tree/v9.6.0#followredirect // options.followRedirect = false; - // https://github.com/sindresorhus/got/tree/v9.6.0#cache - // options.cache = cache; - - // https://github.com/sindresorhus/got/tree/v9.6.0#request - // options.request = request; - - // github.com/sindresorhus/got/tree/v9.6.0#hooks - // options.hooks = hooks; - // use HTTP(S)_PROXY // https://github.com/sindresorhus/got/tree/v9.6.0#agent // options.agent = agent; diff --git a/types/index.d.ts b/types/index.d.ts index 1516b647..01404b7e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -3,13 +3,56 @@ /** * @see https://github.com/panva/node-openid-client/blob/master/docs/README.md */ -import { IncomingMessage } from 'http'; -import { Http2ServerRequest } from 'http2'; +import * as http from 'http'; +import * as https from 'https'; +import * as http2 from 'http2'; +import * as tls from 'tls'; import { JWKS, JSONWebKeySet } from '@panva/jose'; -import { GotOptions } from 'got'; -export type HttpRequestOptions = GotOptions; +export type RetryFunction = (retry: number, error: Error) => number; + +/** + * @see https://github.com/sindresorhus/got/tree/v9.6.0#options + */ +export interface HttpRequestOptions extends tls.SecureContextOptions { + url?: string; + headers?: { + [key: string]: unknown; + }; + query?: { + [key: string]: unknown; + }; + body?: { + [key: string]: unknown; + }; + form?: boolean; + json?: boolean; + timeout?: number | { + lookup?: number; + connect?: number; + secureConnect?: number; + socket?: number; + response?: number; + send?: number; + request?: number; + }; + retry?: number | { + retries?: number | RetryFunction; + methods?: Array<'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'OPTIONS' | 'TRACE'>; + statusCodes?: Array<408 | 413 | 429 | 500 | 502 | 503 | 504>; + maxRetryAfter?: number; + errorCodes?: string[]; + }; + followRedirect?: boolean; + throwHttpErrors?: boolean; + agent?: http.Agent | https.Agent | boolean | { + http: http.Agent, + https: https.Agent, + }; + + [key: string]: unknown; +} export type CustomHttpOptionsProvider = (options: HttpRequestOptions) => HttpRequestOptions; export type TokenTypeHint = 'access_token' | 'refresh_token' | string; @@ -353,7 +396,7 @@ export class Client { * an object. Note: the request read stream will not be parsed, it is expected that you will have a body parser * prior to calling this method. This parser would set the req.body property */ - callbackParams(input: string | IncomingMessage | Http2ServerRequest): CallbackParamsType; + callbackParams(input: string | http.IncomingMessage | http2.Http2ServerRequest): CallbackParamsType; /** * Performs the callback for Authorization Server's authorization response. @@ -606,8 +649,8 @@ export class TokenSet implements TokenSetParameters { export type StrategyVerifyCallbackUserInfo = (tokenset: TokenSet, userinfo: UserinfoResponse, done: (err: any, user?: TUser) => void) => void; export type StrategyVerifyCallback = (tokenset: TokenSet, done: (err: any, user?: TUser) => void) => void; -export type StrategyVerifyCallbackReqUserInfo = (req: IncomingMessage, tokenset: TokenSet, userinfo: UserinfoResponse, done: (err: any, user?: TUser) => void) => void; -export type StrategyVerifyCallbackReq = (req: IncomingMessage, tokenset: TokenSet, done: (err: any, user?: TUser) => void) => void; +export type StrategyVerifyCallbackReqUserInfo = (req: http.IncomingMessage, tokenset: TokenSet, userinfo: UserinfoResponse, done: (err: any, user?: TUser) => void) => void; +export type StrategyVerifyCallbackReq = (req: http.IncomingMessage, tokenset: TokenSet, done: (err: any, user?: TUser) => void) => void; export interface StrategyOptions { client: TClient; @@ -708,9 +751,10 @@ export namespace errors { session_state?: string; /** - * The 'session_state' parameter from the AS response. + * When the error is related to an http(s) request this propetty will hold the response object + * from got. */ - response?: IncomingMessage; + response?: any; } /** @@ -719,10 +763,14 @@ export namespace errors { * checks, jwt, params or body. */ class RPError extends Error { - response?: IncomingMessage; jwt?: string; checks?: object; params?: object; body?: object; + /** + * When the error is related to an http(s) request this propetty will hold the response object + * from got. + */ + response?: any; } }