forked from IdentityModel/oidc-client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
579 lines (475 loc) · 20.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
/* Provides a namespace for when the library is loaded outside a module loader environment */
export as namespace Oidc;
export const Version: string;
export interface Logger {
error(message?: any, ...optionalParams: any[]): void;
info(message?: any, ...optionalParams: any[]): void;
debug(message?: any, ...optionalParams: any[]): void;
warn(message?: any, ...optionalParams: any[]): void;
}
export interface AccessTokenEvents {
load(container: User): void;
unload(): void;
/** Subscribe to events raised prior to the access token expiring */
addAccessTokenExpiring(callback: (...ev: any[]) => void): void;
removeAccessTokenExpiring(callback: (...ev: any[]) => void): void;
/** Subscribe to events raised after the access token has expired */
addAccessTokenExpired(callback: (...ev: any[]) => void): void;
removeAccessTokenExpired(callback: (...ev: any[]) => void): void;
}
export class InMemoryWebStorage {
getItem(key: string): any;
setItem(key: string, value: any): any;
removeItem(key: string): any;
key(index: number): any;
length?: number;
}
export class Log {
static readonly NONE: 0;
static readonly ERROR: 1;
static readonly WARN: 2;
static readonly INFO: 3;
static readonly DEBUG: 4;
static reset(): void;
static level: number;
static logger: Logger;
static debug(message?: any, ...optionalParams: any[]): void;
static info(message?: any, ...optionalParams: any[]): void;
static warn(message?: any, ...optionalParams: any[]): void;
static error(message?: any, ...optionalParams: any[]): void;
}
export interface MetadataService {
new(settings: OidcClientSettings): MetadataService;
metadataUrl?: string;
resetSigningKeys(): void;
getMetadata(): Promise<OidcMetadata>;
getIssuer(): Promise<string>;
getAuthorizationEndpoint(): Promise<string>;
getUserInfoEndpoint(): Promise<string>;
getTokenEndpoint(optional?: boolean): Promise<string | undefined>;
getCheckSessionIframe(): Promise<string | undefined>;
getEndSessionEndpoint(): Promise<string | undefined>;
getRevocationEndpoint(): Promise<string | undefined>;
getKeysEndpoint(): Promise<string | undefined>;
getSigningKeys(): Promise<any[]>;
}
export interface MetadataServiceCtor {
(settings: OidcClientSettings, jsonServiceCtor?: any): MetadataService;
}
export interface ResponseValidator {
validateSigninResponse(state: any, response: any): Promise<SigninResponse>;
validateSignoutResponse(state: any, response: any): Promise<SignoutResponse>;
}
export interface ResponseValidatorCtor {
(settings: OidcClientSettings, metadataServiceCtor?: MetadataServiceCtor, userInfoServiceCtor?: any): ResponseValidator;
}
export interface SigninRequest {
url: string;
state: any;
}
export interface SignoutRequest {
url: string;
state?: any;
}
export class OidcClient {
constructor(settings: OidcClientSettings);
readonly settings: OidcClientSettings;
createSigninRequest(args?: any): Promise<SigninRequest>;
processSigninResponse(url?: string, stateStore?: StateStore): Promise<SigninResponse>;
createSignoutRequest(args?: any): Promise<SignoutRequest>;
processSignoutResponse(url?: string, stateStore?: StateStore): Promise<SignoutResponse>;
clearStaleState(stateStore: StateStore): Promise<any>;
readonly metadataService: MetadataService;
}
export interface OidcClientSettings {
/** The URL of the OIDC/OAuth2 provider */
authority?: string;
readonly metadataUrl?: string;
/** Provide metadata when authority server does not allow CORS on the metadata endpoint */
metadata?: Partial<OidcMetadata>;
/** Provide signingKeys when authority server does not allow CORS on the jwks uri */
signingKeys?: any[];
/** Your client application's identifier as registered with the OIDC/OAuth2 */
client_id?: string;
client_secret?: string;
/** The type of response desired from the OIDC/OAuth2 provider (default: 'id_token') */
readonly response_type?: string;
readonly response_mode?: string;
/** The scope being requested from the OIDC/OAuth2 provider (default: 'openid') */
readonly scope?: string;
/** The redirect URI of your client application to receive a response from the OIDC/OAuth2 provider */
readonly redirect_uri?: string;
/** The OIDC/OAuth2 post-logout redirect URI */
readonly post_logout_redirect_uri?: string;
/** The OIDC/OAuth2 post-logout redirect URI when using popup */
readonly popup_post_logout_redirect_uri?: string;
readonly prompt?: string;
readonly display?: string;
readonly max_age?: number;
readonly ui_locales?: string;
readonly acr_values?: string;
/** Should OIDC protocol claims be removed from profile (default: true) */
readonly filterProtocolClaims?: boolean;
/** Flag to control if additional identity data is loaded from the user info endpoint in order to populate the user's profile (default: true) */
readonly loadUserInfo?: boolean;
/** Number (in seconds) indicating the age of state entries in storage for authorize requests that are considered abandoned and thus can be cleaned up (default: 300) */
readonly staleStateAge?: number;
/** The window of time (in seconds) to allow the current time to deviate when validating id_token's iat, nbf, and exp values (default: 300) */
readonly clockSkew?: number;
readonly clockService?: ClockService;
readonly stateStore?: StateStore;
readonly userInfoJwtIssuer?: 'ANY' | 'OP' | string;
readonly mergeClaims?: boolean;
ResponseValidatorCtor?: ResponseValidatorCtor;
MetadataServiceCtor?: MetadataServiceCtor;
/** An object containing additional query string parameters to be including in the authorization request */
extraQueryParams?: Record<string, any>;
}
export class UserManager extends OidcClient {
constructor(settings: UserManagerSettings);
readonly settings: UserManagerSettings;
/** Removes stale state entries in storage for incomplete authorize requests */
clearStaleState(): Promise<void>;
/** Load the User object for the currently authenticated user */
getUser(): Promise<User | null>;
storeUser(user: User): Promise<void>;
/** Remove from any storage the currently authenticated user */
removeUser(): Promise<void>;
/** Trigger a request (via a popup window) to the authorization endpoint. The result of the promise is the authenticated User */
signinPopup(args?: any): Promise<User>;
/** Notify the opening window of response from the authorization endpoint */
signinPopupCallback(url?: string): Promise<User | undefined>;
/** Trigger a silent request (via an iframe or refreshtoken if available) to the authorization endpoint */
signinSilent(args?: any): Promise<User>;
/** Notify the parent window of response from the authorization endpoint */
signinSilentCallback(url?: string): Promise<User | undefined>;
/** Trigger a redirect of the current window to the authorization endpoint */
signinRedirect(args?: any): Promise<void>;
/** Process response from the authorization endpoint. */
signinRedirectCallback(url?: string): Promise<User>;
/** Trigger a redirect of the current window to the end session endpoint */
signoutRedirect(args?: any): Promise<void>;
/** Process response from the end session endpoint */
signoutRedirectCallback(url?: string): Promise<SignoutResponse>;
/** Trigger a redirect of a popup window window to the end session endpoint */
signoutPopup(args?: any): Promise<void>;
/** Process response from the end session endpoint from a popup window */
signoutPopupCallback(url?: string, keepOpen?: boolean): Promise<void>;
signoutPopupCallback(keepOpen?: boolean): Promise<void>;
/** Proxy to Popup, Redirect and Silent callbacks */
signinCallback(url?: string): Promise<User>;
/** Proxy to Popup and Redirect callbacks */
signoutCallback(url?: string, keepWindowOpen?: boolean): Promise<SignoutResponse | undefined>;
/** Query OP for user's current signin status */
querySessionStatus(args?: any): Promise<SessionStatus>;
revokeAccessToken(): Promise<void>;
/** Enables silent renew */
startSilentRenew(): void;
/** Disables silent renew */
stopSilentRenew(): void;
events: UserManagerEvents;
}
export interface SessionStatus {
/** Opaque session state used to validate if session changed (monitorSession) */
session_state: string;
/** Subject identifier */
sub: string;
/** Session ID */
sid?: string;
}
export interface UserManagerEvents extends AccessTokenEvents {
load(user: User): any;
unload(): any;
/** Subscribe to events raised when user session has been established (or re-established) */
addUserLoaded(callback: UserManagerEvents.UserLoadedCallback): void;
removeUserLoaded(callback: UserManagerEvents.UserLoadedCallback): void;
/** Subscribe to events raised when a user session has been terminated */
addUserUnloaded(callback: UserManagerEvents.UserUnloadedCallback): void;
removeUserUnloaded(callback: UserManagerEvents.UserUnloadedCallback): void;
/** Subscribe to events raised when the automatic silent renew has failed */
addSilentRenewError(callback: UserManagerEvents.SilentRenewErrorCallback): void;
removeSilentRenewError(callback: UserManagerEvents.SilentRenewErrorCallback): void;
/** Subscribe to events raised when the user's signed-in */
addUserSignedIn(callback: UserManagerEvents.UserSignedInCallback): void;
removeUserSignedIn(callback: UserManagerEvents.UserSignedInCallback): void;
/** Subscribe to events raised when the user's sign-in status at the OP has changed */
addUserSignedOut(callback: UserManagerEvents.UserSignedOutCallback): void;
removeUserSignedOut(callback: UserManagerEvents.UserSignedOutCallback): void;
/** When `monitorSession` subscribe to events raised when the user session changed */
addUserSessionChanged(callback: UserManagerEvents.UserSessionChangedCallback): void;
removeUserSessionChanged(callback: UserManagerEvents.UserSessionChangedCallback): void;
}
export namespace UserManagerEvents {
export type UserLoadedCallback = (user: User) => void;
export type UserUnloadedCallback = () => void;
export type SilentRenewErrorCallback = (error: Error) => void;
export type UserSignedInCallback = () => void;
export type UserSignedOutCallback = () => void;
export type UserSessionChangedCallback = () => void;
}
export interface UserManagerSettings extends OidcClientSettings {
/** The URL for the page containing the call to signinPopupCallback to handle the callback from the OIDC/OAuth2 */
readonly popup_redirect_uri?: string;
/** The features parameter to window.open for the popup signin window.
* default: 'location=no,toolbar=no,width=500,height=500,left=100,top=100'
*/
readonly popupWindowFeatures?: string;
/** The target parameter to window.open for the popup signin window (default: '_blank') */
readonly popupWindowTarget?: any;
/** The URL for the page containing the code handling the silent renew */
readonly silent_redirect_uri?: any;
/** Number of milliseconds to wait for the silent renew to return before assuming it has failed or timed out (default: 10000) */
readonly silentRequestTimeout?: any;
/** Flag to indicate if there should be an automatic attempt to renew the access token prior to its expiration (default: false) */
readonly automaticSilentRenew?: boolean;
readonly validateSubOnSilentRenew?: boolean;
/** Flag to control if id_token is included as id_token_hint in silent renew calls (default: true) */
readonly includeIdTokenInSilentRenew?: boolean;
/** Will raise events for when user has performed a signout at the OP (default: true) */
readonly monitorSession?: boolean;
/** Interval, in ms, to check the user's session (default: 2000) */
readonly checkSessionInterval?: number;
readonly query_status_response_type?: string;
readonly stopCheckSessionOnError?: boolean;
/** Will invoke the revocation endpoint on signout if there is an access token for the user (default: false) */
readonly revokeAccessTokenOnSignout?: boolean;
/** The number of seconds before an access token is to expire to raise the accessTokenExpiring event (default: 60) */
readonly accessTokenExpiringNotificationTime?: number;
readonly redirectNavigator?: any;
readonly popupNavigator?: any;
readonly iframeNavigator?: any;
/** Storage object used to persist User for currently authenticated user (default: session storage) */
readonly userStore?: WebStorageStateStore;
}
export interface ClockService {
getEpochTime(): Promise<number>;
}
export interface WebStorageStateStoreSettings {
prefix?: string;
store?: any;
}
export interface StateStore {
set(key: string, value: any): Promise<void>;
get(key: string): Promise<any>;
remove(key: string): Promise<any>;
getAllKeys(): Promise<string[]>;
}
export class WebStorageStateStore implements StateStore {
constructor(settings: WebStorageStateStoreSettings);
set(key: string, value: any): Promise<void>;
get(key: string): Promise<any>;
remove(key: string): Promise<any>;
getAllKeys(): Promise<string[]>;
}
export interface SigninResponse {
new(url: string, delimiter?: string): SigninResponse;
access_token: string;
/** Refresh token returned from the OIDC provider (if requested, via the
* 'offline_access' scope) */
refresh_token?: string;
code: string;
error: string;
error_description: string;
error_uri: string;
id_token: string;
profile: any;
scope: string;
session_state: string;
state: any;
token_type: string;
readonly expired: boolean | undefined;
readonly expires_in: number | undefined;
readonly isOpenIdConnect: boolean;
readonly scopes: string[];
}
export interface SignoutResponse {
new(url: string): SignoutResponse;
error?: string;
error_description?: string;
error_uri?: string;
state?: any;
}
export interface UserSettings {
id_token: string;
session_state: string;
access_token: string;
refresh_token: string;
token_type: string;
scope: string;
profile: Profile;
expires_at: number;
state: any;
}
export class User {
constructor(settings: UserSettings);
/** The id_token returned from the OIDC provider */
id_token: string;
/** The session state value returned from the OIDC provider (opaque) */
session_state?: string;
/** The access token returned from the OIDC provider. */
access_token: string;
/** Refresh token returned from the OIDC provider (if requested) */
refresh_token?: string;
/** The token_type returned from the OIDC provider */
token_type: string;
/** The scope returned from the OIDC provider */
scope: string;
/** The claims represented by a combination of the id_token and the user info endpoint */
profile: Profile;
/** The expires at returned from the OIDC provider */
expires_at: number;
/** The custom state transferred in the last signin */
state: any;
toStorageString(): string;
static fromStorageString(storageString: string): User;
/** Calculated number of seconds the access token has remaining */
readonly expires_in: number;
/** Calculated value indicating if the access token is expired */
readonly expired: boolean;
/** Array representing the parsed values from the scope */
readonly scopes: string[];
}
export type Profile = IDTokenClaims & ProfileStandardClaims;
interface IDTokenClaims {
/** Issuer Identifier */
iss: string;
/** Subject identifier */
sub: string;
/** Audience(s): client_id ... */
aud: string;
/** Expiration time */
exp: number;
/** Issued at */
iat: number;
/** Time when the End-User authentication occurred */
auth_time?: number;
/** Time when the End-User authentication occurred */
nonce?: number;
/** Access Token hash value */
at_hash?: string;
/** Authentication Context Class Reference */
acr?: string;
/** Authentication Methods References */
amr?: string[];
/** Authorized Party - the party to which the ID Token was issued */
azp?: string;
/** Session ID - String identifier for a Session */
sid?: string;
/** Other custom claims */
[claimKey: string]: any;
}
interface ProfileStandardClaims {
/** End-User's full name */
name?: string;
/** Given name(s) or first name(s) of the End-User */
given_name?: string;
/** Surname(s) or last name(s) of the End-User */
family_name?: string;
/** Middle name(s) of the End-User */
middle_name?: string;
/** Casual name of the End-User that may or may not be the same as the given_name. */
nickname?: string;
/** Shorthand name that the End-User wishes to be referred to at the RP, such as janedoe or j.doe. */
preferred_username?: string;
/** URL of the End-User's profile page */
profile?: string;
/** URL of the End-User's profile picture */
picture?: string;
/** URL of the End-User's Web page or blog */
website?: string;
/** End-User's preferred e-mail address */
email?: string;
/** True if the End-User's e-mail address has been verified; otherwise false. */
email_verified?: boolean;
/** End-User's gender. Values defined by this specification are female and male. */
gender?: string;
/** End-User's birthday, represented as an ISO 8601:2004 [ISO8601‑2004] YYYY-MM-DD format */
birthdate?: string;
/** String from zoneinfo [zoneinfo] time zone database representing the End-User's time zone. */
zoneinfo?: string;
/** End-User's locale, represented as a BCP47 [RFC5646] language tag. */
locale?: string;
/** End-User's preferred telephone number. */
phone_number?: string;
/** True if the End-User's phone number has been verified; otherwise false. */
phone_number_verified?: boolean;
/** object End-User's preferred address in JSON [RFC4627] */
address?: OidcAddress;
/** Time the End-User's information was last updated. */
updated_at?: number;
}
interface OidcAddress {
/** Full mailing address, formatted for display or use on a mailing label */
formatted?: string;
/** Full street address component, which MAY include house number, street name, Post Office Box, and multi-line extended street address information */
street_address?: string;
/** City or locality component */
locality?: string;
/** State, province, prefecture, or region component */
region?: string;
/** Zip code or postal code component */
postal_code?: string;
/** Country name component */
country?: string;
}
export class CordovaPopupWindow {
constructor(params: any);
navigate(params: any): Promise<any>;
promise: Promise<any>;
}
export class CordovaPopupNavigator {
prepare(params: any): Promise<CordovaPopupWindow>;
}
export class CordovaIFrameNavigator {
prepare(params: any): Promise<CordovaPopupWindow>;
}
export interface OidcMetadata {
issuer: string;
authorization_endpoint: string;
token_endpoint: string;
token_endpoint_auth_methods_supported: string[];
token_endpoint_auth_signing_alg_values_supported: string[];
userinfo_endpoint: string;
check_session_iframe: string;
end_session_endpoint: string;
jwks_uri: string;
registration_endpoint: string;
scopes_supported: string[];
response_types_supported: string[];
acr_values_supported: string[];
subject_types_supported: string[];
userinfo_signing_alg_values_supported: string[];
userinfo_encryption_alg_values_supported: string[];
userinfo_encryption_enc_values_supported: string[];
id_token_signing_alg_values_supported: string[];
id_token_encryption_alg_values_supported: string[];
id_token_encryption_enc_values_supported: string[];
request_object_signing_alg_values_supported: string[];
display_values_supported: string[];
claim_types_supported: string[];
claims_supported: string[];
claims_parameter_supported: boolean;
service_documentation: string;
ui_locales_supported: string[];
revocation_endpoint: string;
introspection_endpoint: string;
frontchannel_logout_supported: boolean;
frontchannel_logout_session_supported: boolean;
backchannel_logout_supported: boolean;
backchannel_logout_session_supported: boolean;
grant_types_supported: string[];
response_modes_supported: string[];
code_challenge_methods_supported: string[];
}
export interface CheckSessionIFrame {
new(callback: () => void, client_id: string, url: string, interval?: number, stopOnError?: boolean): CheckSessionIFrame
load(): Promise<void>;
start(session_state: string): void;
stop(): void;
}
export interface CheckSessionIFrameCtor {
(callback: () => void, client_id: string, url: string, interval?: number, stopOnError?: boolean): CheckSessionIFrame;
}
export class SessionMonitor {
constructor(userManager: UserManager, CheckSessionIFrameCtor: CheckSessionIFrameCtor);
}