[openid-client] Add introspect() and keystore() (#35530)

* Add Client.introspect() method

* Add Issuer.keystore()

* Add Client.userinfo()
This commit is contained in:
ulrichb
2019-05-17 09:15:39 -07:00
committed by Nathan Shively-Sanders
parent 0d753f7c4c
commit 9d83c3f085
2 changed files with 48 additions and 5 deletions
+11 -1
View File
@@ -2,7 +2,7 @@
// Project: https://github.com/panva/node-openid-client
// Definitions by: ulrichb <https://github.com/ulrichb>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
// TypeScript Version: 3.0
/// <reference types="node" />
@@ -20,6 +20,8 @@ export class Issuer {
readonly metadata: IssuerMetadata;
readonly Client: typeof Client;
keystore(forceReload?: boolean): Promise<unknown>;
}
export interface ClientMetadata {
@@ -68,6 +70,14 @@ export class Client {
}): Promise<TokenSet>;
userinfo(accessToken: string | TokenSet): Promise<{ readonly [name: string]: {} | null | undefined }>;
grant(body: {
readonly grant_type: "authorization_code" | "client_credentials" | "password" | "refresh_token" | string;
readonly [name: string]: string | undefined;
}): Promise<TokenSet>;
introspect(token: string, tokenTypeHint?: string, extras?: { readonly introspectBody?: {} }):
Promise<{ readonly [name: string]: {} | null | undefined }>;
}
export class TokenSet {
+37 -4
View File
@@ -5,6 +5,11 @@ async (req: IncomingMessage) => {
const issuer = await Issuer.discover('https://accounts.google.com');
console.log('Discovered issuer %O', issuer.metadata.issuer);
issuer.keystore();
issuer.keystore(true);
//
const client = new issuer.Client({
client_id: 'c',
client_secret: 's',
@@ -13,10 +18,14 @@ async (req: IncomingMessage) => {
});
console.log(client.metadata.client_id);
//
const code_verifier = generators.codeVerifier();
const code_challenge = generators.codeChallenge(code_verifier);
//
client.authorizationUrl({
scope: 'openid email profile',
response_mode: 'form_post',
@@ -26,14 +35,38 @@ async (req: IncomingMessage) => {
code_challenge_method: 'S256',
}).substring(0);
//
const params = client.callbackParams(req);
const tokenSet = await client.callback('https://client.example.com/callback', params, { code_verifier });
console.log(tokenSet.id_token, tokenSet.access_token, tokenSet.refresh_token);
console.log(tokenSet.expired(), tokenSet.claims()["some claim name"]);
const callbackResponse = await client.callback('https://client.example.com/callback', params, { code_verifier });
console.log(callbackResponse.id_token, callbackResponse.access_token, callbackResponse.refresh_token);
console.log(callbackResponse.expired(), callbackResponse.claims()["some claim name"]);
//
await client.userinfo("access token");
const userinfo = await client.userinfo(tokenSet);
const userinfo = await client.userinfo(callbackResponse);
console.log(userinfo["some user info name"]);
//
const grantResponse = await client.grant({
grant_type: "client_credentials",
acr_values: "acr_values",
});
console.log(grantResponse.access_token);
//
const introspectResponse = await client.introspect("token");
console.log(introspectResponse["some claim name"]);
client.introspect("token", "tokenTypeHint");
client.introspect("token", "tokenTypeHint", {});
client.introspect("token", "tokenTypeHint", { introspectBody: {} });
//
client.endSessionUrl({ id_token_hint: "id_token_hint" }).substring(0);
};