mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
Add custom HTTP request options API for Issuer c'tor and Client instance (#36645)
* Add custom HTTP request options API for Issuer c'tor and Client instance * Disable automatic export of all module members (make it explicit) * Add `custom.http_options` also for Issuer instance and Client c'tor
This commit is contained in:
Vendored
+21
@@ -8,6 +8,18 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import { IncomingMessage } from 'http';
|
||||
import { GotOptions } from 'got';
|
||||
|
||||
export { }; // Disable automatic export of all module members (make it explicit)
|
||||
|
||||
//
|
||||
|
||||
type HttpRequestOptions = GotOptions<null>;
|
||||
type CustomHttpOptionsProvider = (options: HttpRequestOptions) => HttpRequestOptions;
|
||||
|
||||
export const custom: {
|
||||
readonly http_options: unique symbol,
|
||||
};
|
||||
|
||||
// https://github.com/panva/node-openid-client/tree/master/docs#issuer
|
||||
|
||||
@@ -36,9 +48,14 @@ export interface IssuerMetadata {
|
||||
}
|
||||
|
||||
export class Issuer {
|
||||
static [custom.http_options]: CustomHttpOptionsProvider;
|
||||
|
||||
constructor(metadata?: IssuerMetadata);
|
||||
|
||||
static discover(issuer: string): Promise<Issuer>;
|
||||
|
||||
[custom.http_options]: CustomHttpOptionsProvider;
|
||||
|
||||
readonly metadata: IssuerMetadata;
|
||||
|
||||
readonly Client: typeof Client;
|
||||
@@ -73,8 +90,12 @@ export interface EndSessionUrlParameters {
|
||||
}
|
||||
|
||||
export class Client {
|
||||
static [custom.http_options]: CustomHttpOptionsProvider;
|
||||
|
||||
constructor(metadata?: ClientMetadata);
|
||||
|
||||
[custom.http_options]: CustomHttpOptionsProvider;
|
||||
|
||||
readonly metadata: ClientMetadata;
|
||||
|
||||
authorizationUrl(parameters?: AuthorizationUrlParameters): string;
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
import { IncomingMessage } from 'http';
|
||||
import { Issuer, generators } from 'openid-client';
|
||||
import { Issuer, generators, custom } from 'openid-client';
|
||||
|
||||
async (req: IncomingMessage) => {
|
||||
// Custom HTTP options on the `Issuer` _c'tor_ (e.g. used for `Issuer.discover()`):
|
||||
Issuer[custom.http_options] = options => {
|
||||
console.log(options.followRedirect, options.timeout, options.retry);
|
||||
return {
|
||||
...options,
|
||||
followRedirect: true,
|
||||
timeout: 10_000,
|
||||
retry: 3,
|
||||
};
|
||||
};
|
||||
|
||||
let issuer = await Issuer.discover('https://accounts.google.com');
|
||||
console.log('Discovered issuer %O', issuer.metadata.issuer);
|
||||
|
||||
@@ -19,8 +30,12 @@ async (req: IncomingMessage) => {
|
||||
token_endpoint_auth_methods_supported: ['client_secret_post', 'client_secret_basic'],
|
||||
});
|
||||
|
||||
issuer[custom.http_options] = options => ({ ...options, retry: 3 });
|
||||
|
||||
//
|
||||
|
||||
issuer.Client[custom.http_options] = options => ({ ...options, retry: 3 });
|
||||
|
||||
const client = new issuer.Client({
|
||||
client_id: 'c',
|
||||
client_secret: 's',
|
||||
@@ -29,6 +44,9 @@ async (req: IncomingMessage) => {
|
||||
});
|
||||
console.log(client.metadata.client_id);
|
||||
|
||||
// Custom HTTP options on the `Client` _instance_
|
||||
client[custom.http_options] = options => ({ ...options, retry: 3 });
|
||||
|
||||
//
|
||||
|
||||
const code_verifier = generators.codeVerifier();
|
||||
|
||||
Reference in New Issue
Block a user