From d1974b1eeb649e5b02cbcf32d7a97d64ad76e299 Mon Sep 17 00:00:00 2001 From: Richard Honor Date: Fri, 2 Aug 2019 22:30:07 +0100 Subject: [PATCH] [openid-client] Add more detailed types to introspection response as per RFC7662 (#37319) * [openid-client] add more detailed types to introspection respose * [openid-client] scope type as string * Make additional responses unknown, and make types readonly --- types/openid-client/index.d.ts | 19 ++++++++++++++++++- types/openid-client/openid-client-tests.ts | 7 ++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/types/openid-client/index.d.ts b/types/openid-client/index.d.ts index 4ab686ab42..0d5b3c8122 100644 --- a/types/openid-client/index.d.ts +++ b/types/openid-client/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/panva/node-openid-client // Definitions by: ulrichb // Brandon Shelton +// Richard Honor // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 @@ -89,6 +90,22 @@ export interface EndSessionUrlParameters { readonly state?: string; } +export interface IntrospectionResponse { + readonly active: boolean; + readonly scope?: string; + readonly client_id?: string; + readonly username?: string; + readonly token_type?: string; + readonly exp?: number; + readonly iat?: number; + readonly nbf?: number; + readonly sub?: string; + readonly aud?: string; + readonly iss?: string; + readonly jti?: string; + readonly [key: string]: unknown; +} + export class Client { static [custom.http_options]: CustomHttpOptionsProvider; @@ -127,7 +144,7 @@ export class Client { token: string, tokenTypeHint?: string, extras?: { readonly introspectBody?: object } - ): Promise<{ readonly [name: string]: {} | null | undefined }>; + ): Promise; } export class TokenSet { diff --git a/types/openid-client/openid-client-tests.ts b/types/openid-client/openid-client-tests.ts index 9ee8784a4a..0dc135a8b1 100644 --- a/types/openid-client/openid-client-tests.ts +++ b/types/openid-client/openid-client-tests.ts @@ -1,5 +1,9 @@ import { IncomingMessage } from 'http'; -import { Issuer, generators, custom } from 'openid-client'; +import { + custom, + generators, + Issuer, +} from 'openid-client'; async (req: IncomingMessage) => { // Custom HTTP options on the `Issuer` _c'tor_ (e.g. used for `Issuer.discover()`): @@ -90,6 +94,7 @@ async (req: IncomingMessage) => { // const introspectResponse = await client.introspect('token'); + const active: boolean = introspectResponse.active; console.log(introspectResponse['some claim name']); client.introspect('token', 'tokenTypeHint');