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
197 lines (165 loc) · 8.85 KB
/
Copy pathUserManagerSettings.ts
File metadata and controls
197 lines (165 loc) · 8.85 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
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
// 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 { type OidcClientSettings, OidcClientSettingsStore } from "./OidcClientSettings";
import type { PopupWindowFeatures } from "./utils/PopupUtils";
import { WebStorageStateStore } from "./WebStorageStateStore";
import { InMemoryWebStorage } from "./InMemoryWebStorage";
export const DefaultPopupWindowFeatures: PopupWindowFeatures = {
location: false,
toolbar: false,
height: 640,
closePopupWindowAfterInSeconds: -1,
};
export const DefaultPopupTarget = "_blank";
const DefaultAccessTokenExpiringNotificationTimeInSeconds = 60;
const DefaultCheckSessionIntervalInSeconds = 2;
export const DefaultSilentRequestTimeoutInSeconds = 10;
/**
* 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, closePopupWindowAfterInSeconds: -1 \})
*/
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 methods target window being redirected (default: "self") */
redirectTarget?: "top" | "self";
/** The target to pass while calling postMessage inside iframe for callback (default: window.location.origin) */
iframeNotifyParentOrigin?: string;
/** The script origin to check during 'message' callback execution while performing silent auth via iframe (default: window.location.origin) */
iframeScriptOrigin?: string;
/** 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. The automatic renew attempt starts 1 minute before the access token expires (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;
/** Flag to control if id_token is included as id_token_hint in silent signout calls (default: false) */
includeIdTokenInSilentSignout?: 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;
public readonly popup_post_logout_redirect_uri: string | undefined;
public readonly popupWindowFeatures: PopupWindowFeatures;
public readonly popupWindowTarget: string;
public readonly redirectMethod: "replace" | "assign";
public readonly redirectTarget: "top" | "self";
public readonly iframeNotifyParentOrigin: string | undefined;
public readonly iframeScriptOrigin: string | undefined;
public readonly silent_redirect_uri: string;
public readonly silentRequestTimeoutInSeconds: number;
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;
public readonly stopCheckSessionOnError: boolean;
public readonly revokeTokenTypes: ("access_token" | "refresh_token")[];
public readonly revokeTokensOnSignout: boolean;
public readonly includeIdTokenInSilentSignout: boolean;
public readonly accessTokenExpiringNotificationTimeInSeconds: number;
public readonly userStore: WebStorageStateStore;
public constructor(args: UserManagerSettings) {
const {
popup_redirect_uri = args.redirect_uri,
popup_post_logout_redirect_uri = args.post_logout_redirect_uri,
popupWindowFeatures = DefaultPopupWindowFeatures,
popupWindowTarget = DefaultPopupTarget,
redirectMethod = "assign",
redirectTarget = "self",
iframeNotifyParentOrigin = args.iframeNotifyParentOrigin,
iframeScriptOrigin = args.iframeScriptOrigin,
requestTimeoutInSeconds,
silent_redirect_uri = args.redirect_uri,
silentRequestTimeoutInSeconds,
automaticSilentRenew = true,
validateSubOnSilentRenew = true,
includeIdTokenInSilentRenew = false,
monitorSession = false,
monitorAnonymousSession = false,
checkSessionIntervalInSeconds = DefaultCheckSessionIntervalInSeconds,
query_status_response_type = "code",
stopCheckSessionOnError = true,
revokeTokenTypes = ["access_token", "refresh_token"],
revokeTokensOnSignout = false,
includeIdTokenInSilentSignout = 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.redirectTarget = redirectTarget;
this.iframeNotifyParentOrigin = iframeNotifyParentOrigin;
this.iframeScriptOrigin = iframeScriptOrigin;
this.silent_redirect_uri = silent_redirect_uri;
this.silentRequestTimeoutInSeconds = silentRequestTimeoutInSeconds || requestTimeoutInSeconds || DefaultSilentRequestTimeoutInSeconds;
this.automaticSilentRenew = automaticSilentRenew;
this.validateSubOnSilentRenew = validateSubOnSilentRenew;
this.includeIdTokenInSilentRenew = includeIdTokenInSilentRenew;
this.monitorSession = monitorSession;
this.monitorAnonymousSession = monitorAnonymousSession;
this.checkSessionIntervalInSeconds = checkSessionIntervalInSeconds;
this.stopCheckSessionOnError = stopCheckSessionOnError;
this.query_status_response_type = query_status_response_type;
this.revokeTokenTypes = revokeTokenTypes;
this.revokeTokensOnSignout = revokeTokensOnSignout;
this.includeIdTokenInSilentSignout = includeIdTokenInSilentSignout;
this.accessTokenExpiringNotificationTimeInSeconds = accessTokenExpiringNotificationTimeInSeconds;
if (userStore) {
this.userStore = userStore;
}
else {
const store = typeof window !== "undefined" ? window.sessionStorage : new InMemoryWebStorage();
this.userStore = new WebStorageStateStore({ store });
}
}
}