forked from authts/oidc-client-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserManagerSettings.ts
More file actions
164 lines (141 loc) · 7.16 KB
/
Copy pathUserManagerSettings.ts
File metadata and controls
164 lines (141 loc) · 7.16 KB
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
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
import { OidcClientSettings, OidcClientSettingsStore } from "./OidcClientSettings";
import type { PopupWindowFeatures } from "./utils";
import { WebStorageStateStore } from "./WebStorageStateStore";
import { InMemoryWebStorage } from "./InMemoryWebStorage";
const DefaultAccessTokenExpiringNotificationTimeInSeconds = 60;
const DefaultCheckSessionIntervalInSeconds = 2;
/**
* The settings used to configure the {@link UserManager}.
*
* @public
*/
export interface UserManagerSettings extends OidcClientSettings {
/** The URL for the page containing the call to signinPopupCallback to handle the callback from the OIDC/OAuth2 */
popup_redirect_uri?: string;
popup_post_logout_redirect_uri?: string;
/**
* The features parameter to window.open for the popup signin window. By default, the popup is
* placed centered in front of the window opener.
* (default: \{ location: false, menubar: false, height: 640 \})
*/
popupWindowFeatures?: PopupWindowFeatures;
/** The target parameter to window.open for the popup signin window (default: "_blank") */
popupWindowTarget?: string;
/** The methods window.location method used to redirect (default: "assign") */
redirectMethod?: "replace" | "assign";
/** The URL for the page containing the code handling the silent renew */
silent_redirect_uri?: string;
/** Number of seconds to wait for the silent renew to return before assuming it has failed or timed out (default: 10) */
silentRequestTimeoutInSeconds?: number;
/** Flag to indicate if there should be an automatic attempt to renew the access token prior to its expiration (default: true) */
automaticSilentRenew?: boolean;
/** Flag to validate user.profile.sub in silent renew calls (default: true) */
validateSubOnSilentRenew?: boolean;
/** Flag to control if id_token is included as id_token_hint in silent renew calls (default: false) */
includeIdTokenInSilentRenew?: boolean;
/** Will raise events for when user has performed a signout at the OP (default: false) */
monitorSession?: boolean;
monitorAnonymousSession?: boolean;
/** Interval in seconds to check the user's session (default: 2) */
checkSessionIntervalInSeconds?: number;
query_status_response_type?: string;
stopCheckSessionOnError?: boolean;
/**
* The `token_type_hint`s to pass to the authority server by default (default: ["access_token", "refresh_token"])
*
* Token types will be revoked in the same order as they are given here.
*/
revokeTokenTypes?: ("access_token" | "refresh_token")[];
/** Will invoke the revocation endpoint on signout if there is an access token for the user (default: false) */
revokeTokensOnSignout?: boolean;
/** The number of seconds before an access token is to expire to raise the accessTokenExpiring event (default: 60) */
accessTokenExpiringNotificationTimeInSeconds?: number;
/**
* Storage object used to persist User for currently authenticated user (default: window.sessionStorage, InMemoryWebStorage iff no window).
* E.g. `userStore: new WebStorageStateStore({ store: window.localStorage })`
*/
userStore?: WebStorageStateStore;
}
/**
* The settings with defaults applied of the {@link UserManager}.
* @see {@link UserManagerSettings}
*
* @public
*/
export class UserManagerSettingsStore extends OidcClientSettingsStore {
public readonly popup_redirect_uri: string | undefined;
public readonly popup_post_logout_redirect_uri: string | undefined;
public readonly popupWindowFeatures: PopupWindowFeatures | undefined;
public readonly popupWindowTarget: string | undefined;
public readonly redirectMethod: "replace" | "assign";
public readonly silent_redirect_uri: string | undefined;
public readonly silentRequestTimeoutInSeconds: number | undefined;
public readonly automaticSilentRenew: boolean;
public readonly validateSubOnSilentRenew: boolean;
public readonly includeIdTokenInSilentRenew: boolean;
public readonly monitorSession: boolean;
public readonly monitorAnonymousSession: boolean;
public readonly checkSessionIntervalInSeconds: number;
public readonly query_status_response_type: string | undefined;
public readonly stopCheckSessionOnError: boolean;
public readonly revokeTokenTypes: ("access_token" | "refresh_token")[];
public readonly revokeTokensOnSignout: boolean;
public readonly accessTokenExpiringNotificationTimeInSeconds: number;
public readonly userStore: WebStorageStateStore;
public constructor(args: UserManagerSettings) {
const {
popup_redirect_uri,
popup_post_logout_redirect_uri,
popupWindowFeatures,
popupWindowTarget,
redirectMethod = "assign",
silent_redirect_uri,
silentRequestTimeoutInSeconds,
automaticSilentRenew = true,
validateSubOnSilentRenew = true,
includeIdTokenInSilentRenew = false,
monitorSession = false,
monitorAnonymousSession = false,
checkSessionIntervalInSeconds = DefaultCheckSessionIntervalInSeconds,
query_status_response_type,
stopCheckSessionOnError = true,
revokeTokenTypes = ["access_token", "refresh_token"],
revokeTokensOnSignout = false,
accessTokenExpiringNotificationTimeInSeconds = DefaultAccessTokenExpiringNotificationTimeInSeconds,
userStore,
} = args;
super(args);
this.popup_redirect_uri = popup_redirect_uri;
this.popup_post_logout_redirect_uri = popup_post_logout_redirect_uri;
this.popupWindowFeatures = popupWindowFeatures;
this.popupWindowTarget = popupWindowTarget;
this.redirectMethod = redirectMethod;
this.silent_redirect_uri = silent_redirect_uri;
this.silentRequestTimeoutInSeconds = silentRequestTimeoutInSeconds;
this.automaticSilentRenew = automaticSilentRenew;
this.validateSubOnSilentRenew = validateSubOnSilentRenew;
this.includeIdTokenInSilentRenew = includeIdTokenInSilentRenew;
this.monitorSession = monitorSession;
this.monitorAnonymousSession = monitorAnonymousSession;
this.checkSessionIntervalInSeconds = checkSessionIntervalInSeconds;
this.stopCheckSessionOnError = stopCheckSessionOnError;
if (query_status_response_type) {
this.query_status_response_type = query_status_response_type;
}
else {
this.query_status_response_type = "code";
}
this.revokeTokenTypes = revokeTokenTypes;
this.revokeTokensOnSignout = revokeTokensOnSignout;
this.accessTokenExpiringNotificationTimeInSeconds = accessTokenExpiringNotificationTimeInSeconds;
if (userStore) {
this.userStore = userStore;
}
else {
const store = typeof window !== "undefined" ? window.sessionStorage : new InMemoryWebStorage();
this.userStore = new WebStorageStateStore({ store });
}
}
}