[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
This commit is contained in:
Richard Honor 2019-08-02 22:30:07 +01:00 committed by Jesse Trinity
parent 641126b0a7
commit d1974b1eeb
2 changed files with 24 additions and 2 deletions

View File

@ -2,6 +2,7 @@
// Project: https://github.com/panva/node-openid-client
// Definitions by: ulrichb <https://github.com/ulrichb>
// Brandon Shelton <https://github.com/YangusKhan>
// Richard Honor <https://github.com/RMHonor>
// 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<IntrospectionResponse>;
}
export class TokenSet {

View File

@ -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');