@phila/sso-core 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +468 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +264 -173
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,58 +1,67 @@
|
|
|
1
|
-
import { LogLevel
|
|
2
|
-
class
|
|
1
|
+
import { LogLevel, PublicClientApplication, InteractionRequiredAuthError } from "@azure/msal-browser";
|
|
2
|
+
class SSOEventEmitter {
|
|
3
3
|
listeners = /* @__PURE__ */ new Map();
|
|
4
|
-
on(
|
|
5
|
-
this.listeners.has(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
on(event, listener) {
|
|
5
|
+
if (!this.listeners.has(event)) {
|
|
6
|
+
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
7
|
+
}
|
|
8
|
+
const set = this.listeners.get(event);
|
|
9
|
+
set.add(listener);
|
|
10
|
+
return () => {
|
|
11
|
+
set.delete(listener);
|
|
9
12
|
};
|
|
10
13
|
}
|
|
11
|
-
emit(
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
for (const
|
|
15
|
-
|
|
14
|
+
emit(event, data) {
|
|
15
|
+
const set = this.listeners.get(event);
|
|
16
|
+
if (set) {
|
|
17
|
+
for (const listener of set) {
|
|
18
|
+
listener(data);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
16
21
|
}
|
|
17
22
|
removeAllListeners() {
|
|
18
23
|
this.listeners.clear();
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
|
-
const
|
|
26
|
+
const DEFAULT_POLICIES = {
|
|
22
27
|
SIGN_UP_SIGN_IN: "B2C_1A_SIGNUP_SIGNIN",
|
|
23
28
|
SIGN_IN_ONLY: "B2C_1A_AD_SIGNIN_ONLY",
|
|
24
29
|
RESET_PASSWORD: "B2C_1A_PASSWORDRESET"
|
|
25
|
-
}
|
|
30
|
+
};
|
|
31
|
+
const DEFAULT_SCOPES = {
|
|
26
32
|
OPENID: "openid",
|
|
27
33
|
PROFILE: "profile",
|
|
28
34
|
OFFLINE_ACCESS: "offline_access"
|
|
29
|
-
}
|
|
35
|
+
};
|
|
36
|
+
const CACHE_CONFIG = {
|
|
30
37
|
LOCATION: "sessionStorage",
|
|
31
|
-
STORE_AUTH_STATE_IN_COOKIE:
|
|
32
|
-
}
|
|
38
|
+
STORE_AUTH_STATE_IN_COOKIE: false
|
|
39
|
+
};
|
|
40
|
+
const MSAL_ERROR_CODES = {
|
|
33
41
|
USER_CANCELLED: "user_cancelled",
|
|
34
42
|
NO_CACHED_AUTHORITY: "no_cached_authority_error",
|
|
35
43
|
INTERACTION_REQUIRED: "interaction_required",
|
|
36
44
|
FORGOT_PASSWORD: "AADB2C90118"
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
};
|
|
46
|
+
const STATE_SEPARATOR = "|";
|
|
47
|
+
function encodeState(stateObj) {
|
|
48
|
+
return btoa(JSON.stringify(stateObj));
|
|
40
49
|
}
|
|
41
|
-
function
|
|
50
|
+
function decodeState(encoded) {
|
|
42
51
|
try {
|
|
43
|
-
return JSON.parse(atob(
|
|
52
|
+
return JSON.parse(atob(encoded));
|
|
44
53
|
} catch {
|
|
45
54
|
return null;
|
|
46
55
|
}
|
|
47
56
|
}
|
|
48
|
-
function
|
|
49
|
-
if (!
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
const
|
|
53
|
-
return
|
|
57
|
+
function extractCustomState(msalState) {
|
|
58
|
+
if (!msalState) return null;
|
|
59
|
+
const parts = msalState.split(STATE_SEPARATOR);
|
|
60
|
+
if (parts.length < 2) return null;
|
|
61
|
+
const customPart = parts.slice(1).join(STATE_SEPARATOR);
|
|
62
|
+
return decodeState(customPart);
|
|
54
63
|
}
|
|
55
|
-
class
|
|
64
|
+
class B2CProvider {
|
|
56
65
|
type = "b2c";
|
|
57
66
|
clientId;
|
|
58
67
|
b2cEnv;
|
|
@@ -62,12 +71,19 @@ class a {
|
|
|
62
71
|
policies;
|
|
63
72
|
apiScopes;
|
|
64
73
|
cacheLocation;
|
|
65
|
-
constructor(
|
|
66
|
-
this.clientId =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
constructor(config) {
|
|
75
|
+
this.clientId = config.clientId;
|
|
76
|
+
this.b2cEnv = config.b2cEnvironment;
|
|
77
|
+
this.authorityDomain = config.authorityDomain;
|
|
78
|
+
this.redirectUri = config.redirectUri;
|
|
79
|
+
this.postLogoutRedirectUri = config.postLogoutRedirectUri ?? config.redirectUri;
|
|
80
|
+
this.policies = {
|
|
81
|
+
signUpSignIn: config.policies?.signUpSignIn ?? DEFAULT_POLICIES.SIGN_UP_SIGN_IN,
|
|
82
|
+
signInOnly: config.policies?.signInOnly ?? DEFAULT_POLICIES.SIGN_IN_ONLY,
|
|
83
|
+
resetPassword: config.policies?.resetPassword ?? DEFAULT_POLICIES.RESET_PASSWORD
|
|
84
|
+
};
|
|
85
|
+
this.apiScopes = config.apiScopes ?? [];
|
|
86
|
+
this.cacheLocation = config.cacheLocation ?? CACHE_CONFIG.LOCATION;
|
|
71
87
|
}
|
|
72
88
|
buildMsalConfig() {
|
|
73
89
|
return {
|
|
@@ -77,35 +93,37 @@ class a {
|
|
|
77
93
|
knownAuthorities: this.getKnownAuthorities(),
|
|
78
94
|
redirectUri: this.redirectUri,
|
|
79
95
|
postLogoutRedirectUri: this.postLogoutRedirectUri,
|
|
80
|
-
navigateToLoginRequestUrl:
|
|
96
|
+
navigateToLoginRequestUrl: false
|
|
81
97
|
},
|
|
82
98
|
cache: {
|
|
83
99
|
cacheLocation: this.cacheLocation,
|
|
84
|
-
storeAuthStateInCookie:
|
|
100
|
+
storeAuthStateInCookie: CACHE_CONFIG.STORE_AUTH_STATE_IN_COOKIE
|
|
85
101
|
},
|
|
86
102
|
system: {
|
|
87
103
|
loggerOptions: {
|
|
88
|
-
logLevel:
|
|
89
|
-
loggerCallback: (
|
|
90
|
-
console.warn("[sso-core/b2c]",
|
|
104
|
+
logLevel: LogLevel.Warning,
|
|
105
|
+
loggerCallback: (_level, message) => {
|
|
106
|
+
console.warn("[sso-core/b2c]", message);
|
|
91
107
|
}
|
|
92
108
|
}
|
|
93
109
|
}
|
|
94
110
|
};
|
|
95
111
|
}
|
|
96
|
-
getAuthority(
|
|
97
|
-
const
|
|
98
|
-
return `https://${this.authorityDomain}/${this.b2cEnv}.onmicrosoft.com/${
|
|
112
|
+
getAuthority(policy) {
|
|
113
|
+
const p = policy ?? this.policies.signUpSignIn;
|
|
114
|
+
return `https://${this.authorityDomain}/${this.b2cEnv}.onmicrosoft.com/${p}`;
|
|
99
115
|
}
|
|
100
116
|
getKnownAuthorities() {
|
|
101
117
|
return [this.authorityDomain];
|
|
102
118
|
}
|
|
103
|
-
identifyPolicy(
|
|
104
|
-
const
|
|
105
|
-
|
|
119
|
+
identifyPolicy(response) {
|
|
120
|
+
const claims = response.idTokenClaims;
|
|
121
|
+
if (!claims) return null;
|
|
122
|
+
const acr = claims.acr ?? claims.tfp;
|
|
123
|
+
return acr?.toUpperCase() ?? null;
|
|
106
124
|
}
|
|
107
125
|
getDefaultScopes() {
|
|
108
|
-
return [
|
|
126
|
+
return [DEFAULT_SCOPES.OPENID, DEFAULT_SCOPES.PROFILE];
|
|
109
127
|
}
|
|
110
128
|
getApiScopes() {
|
|
111
129
|
return this.apiScopes;
|
|
@@ -123,174 +141,247 @@ class a {
|
|
|
123
141
|
return this.policies;
|
|
124
142
|
}
|
|
125
143
|
}
|
|
126
|
-
const
|
|
127
|
-
isAuthenticated:
|
|
128
|
-
isLoading:
|
|
144
|
+
const INITIAL_STATE = {
|
|
145
|
+
isAuthenticated: false,
|
|
146
|
+
isLoading: false,
|
|
129
147
|
user: null,
|
|
130
148
|
token: null,
|
|
131
149
|
error: null,
|
|
132
150
|
activePolicy: null,
|
|
133
|
-
authReady:
|
|
151
|
+
authReady: false
|
|
134
152
|
};
|
|
135
|
-
class
|
|
136
|
-
events = new
|
|
153
|
+
class SSOClient {
|
|
154
|
+
events = new SSOEventEmitter();
|
|
137
155
|
provider;
|
|
138
156
|
debug;
|
|
139
157
|
encodedState;
|
|
140
158
|
msalInstance = null;
|
|
141
|
-
_state = { ...
|
|
142
|
-
constructor(
|
|
143
|
-
this.provider =
|
|
159
|
+
_state = { ...INITIAL_STATE };
|
|
160
|
+
constructor(config) {
|
|
161
|
+
this.provider = config.provider;
|
|
162
|
+
this.debug = config.debug ?? false;
|
|
163
|
+
this.encodedState = config.state ? encodeState(config.state) : null;
|
|
144
164
|
}
|
|
145
165
|
get state() {
|
|
146
166
|
return this._state;
|
|
147
167
|
}
|
|
148
168
|
// ── Lifecycle ──
|
|
149
169
|
async initialize() {
|
|
150
|
-
this.log("Initializing SSOClient...")
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
170
|
+
this.log("Initializing SSOClient...");
|
|
171
|
+
this.updateState({ isLoading: true });
|
|
172
|
+
const msalConfig = this.provider.buildMsalConfig();
|
|
173
|
+
this.msalInstance = new PublicClientApplication(msalConfig);
|
|
174
|
+
await this.msalInstance.initialize();
|
|
175
|
+
const result = await this.handleRedirect();
|
|
176
|
+
this.updateState({ isLoading: false, authReady: true });
|
|
177
|
+
return result;
|
|
155
178
|
}
|
|
156
179
|
destroy() {
|
|
157
|
-
this.events.removeAllListeners()
|
|
180
|
+
this.events.removeAllListeners();
|
|
181
|
+
this.msalInstance = null;
|
|
182
|
+
this._state = { ...INITIAL_STATE };
|
|
158
183
|
}
|
|
159
184
|
// ── Auth Actions ──
|
|
160
185
|
async handleRedirect() {
|
|
161
|
-
this.assertInitialized()
|
|
186
|
+
this.assertInitialized();
|
|
187
|
+
this.log("Handling redirect promise...");
|
|
162
188
|
try {
|
|
163
|
-
const
|
|
164
|
-
if (!
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
189
|
+
const response = await this.msalInstance.handleRedirectPromise();
|
|
190
|
+
if (!response) {
|
|
191
|
+
this.selectAccount(null);
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
this.log("Redirect response received", response);
|
|
195
|
+
const customState = extractCustomState(response.state);
|
|
196
|
+
const policy = this.provider.identifyPolicy(response);
|
|
197
|
+
this.updateState({ activePolicy: policy });
|
|
198
|
+
if (this.isForgotPasswordPolicy(policy)) {
|
|
199
|
+
this.log("Forgot password flow completed");
|
|
200
|
+
this.events.emit("auth:forgotPassword", void 0);
|
|
201
|
+
return { ...response, customPostbackObject: customState ?? void 0 };
|
|
202
|
+
}
|
|
203
|
+
this.updateState({ isLoading: true });
|
|
204
|
+
this.selectAccount(policy);
|
|
205
|
+
await this.acquireTokenAfterRedirect(response);
|
|
206
|
+
const authResponse = {
|
|
207
|
+
...response,
|
|
208
|
+
customPostbackObject: customState ?? void 0
|
|
174
209
|
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
210
|
+
this.events.emit("auth:signedIn", authResponse);
|
|
211
|
+
return authResponse;
|
|
212
|
+
} catch (error) {
|
|
213
|
+
return this.handleRedirectError(error);
|
|
178
214
|
}
|
|
179
215
|
}
|
|
180
|
-
async signIn(
|
|
181
|
-
this.assertInitialized()
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
216
|
+
async signIn(options) {
|
|
217
|
+
this.assertInitialized();
|
|
218
|
+
this.log("Initiating sign-in...");
|
|
219
|
+
this.updateState({ isLoading: true });
|
|
220
|
+
this.events.emit("auth:loading", true);
|
|
221
|
+
const request = this.buildLoginRequest(this.provider.getAuthority(), options);
|
|
222
|
+
await this.msalInstance.loginRedirect(request);
|
|
223
|
+
}
|
|
224
|
+
async signInCityEmployee(options) {
|
|
225
|
+
this.assertInitialized();
|
|
226
|
+
this.log("Initiating city employee sign-in...");
|
|
227
|
+
if (!(this.provider instanceof B2CProvider)) {
|
|
228
|
+
return this.signIn(options);
|
|
229
|
+
}
|
|
230
|
+
const authority = this.provider.getSignInOnlyAuthority();
|
|
231
|
+
const request = this.buildLoginRequest(authority, options);
|
|
232
|
+
await this.msalInstance.loginRedirect(request);
|
|
233
|
+
}
|
|
234
|
+
async signOut(options) {
|
|
235
|
+
this.assertInitialized();
|
|
236
|
+
this.log("Initiating sign-out...");
|
|
237
|
+
const logoutRequest = {
|
|
238
|
+
postLogoutRedirectUri: options?.postLogoutRedirectUri,
|
|
195
239
|
authority: this.provider.getAuthority()
|
|
196
240
|
};
|
|
197
|
-
this.updateState({ isLoading:
|
|
241
|
+
this.updateState({ isLoading: true });
|
|
242
|
+
this.events.emit("auth:signedOut", void 0);
|
|
243
|
+
await this.msalInstance.logoutRedirect(logoutRequest);
|
|
198
244
|
}
|
|
199
245
|
async forgotPassword() {
|
|
200
|
-
|
|
246
|
+
this.assertInitialized();
|
|
247
|
+
if (!(this.provider instanceof B2CProvider)) {
|
|
201
248
|
this.log("Forgot password is only supported for B2C providers");
|
|
202
249
|
return;
|
|
203
250
|
}
|
|
204
251
|
this.log("Initiating forgot password flow...");
|
|
205
|
-
const
|
|
206
|
-
await this.msalInstance.loginRedirect({ scopes: [], authority
|
|
207
|
-
}
|
|
208
|
-
async acquireToken(
|
|
209
|
-
this.assertInitialized()
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
252
|
+
const authority = this.provider.getResetPasswordAuthority();
|
|
253
|
+
await this.msalInstance.loginRedirect({ scopes: [], authority });
|
|
254
|
+
}
|
|
255
|
+
async acquireToken(options) {
|
|
256
|
+
this.assertInitialized();
|
|
257
|
+
this.log("Acquiring token...");
|
|
258
|
+
const account = this._state.user;
|
|
259
|
+
if (!account) {
|
|
260
|
+
this.log("No account found, cannot acquire token");
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
const scopes = options?.scopes ?? this.provider.getApiScopes();
|
|
264
|
+
const tokenRequest = {
|
|
265
|
+
scopes,
|
|
266
|
+
forceRefresh: options?.forceRefresh ?? false,
|
|
267
|
+
account,
|
|
217
268
|
authority: this._state.activePolicy ? this.provider.getAuthority(this._state.activePolicy) : this.provider.getAuthority()
|
|
218
269
|
};
|
|
219
270
|
try {
|
|
220
|
-
const
|
|
221
|
-
if (!
|
|
222
|
-
throw new
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
271
|
+
const response = await this.msalInstance.acquireTokenSilent(tokenRequest);
|
|
272
|
+
if (!response.accessToken) {
|
|
273
|
+
throw new InteractionRequiredAuthError("empty_token");
|
|
274
|
+
}
|
|
275
|
+
this.log("Token acquired silently");
|
|
276
|
+
this.updateState({ token: response.accessToken, error: null });
|
|
277
|
+
this.events.emit("auth:tokenAcquired", response.accessToken);
|
|
278
|
+
return response.accessToken;
|
|
279
|
+
} catch (error) {
|
|
280
|
+
if (error instanceof InteractionRequiredAuthError) {
|
|
226
281
|
this.log("Silent token acquisition failed, falling back to redirect");
|
|
227
282
|
try {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
283
|
+
await this.msalInstance.acquireTokenRedirect(tokenRequest);
|
|
284
|
+
return null;
|
|
285
|
+
} catch (redirectError) {
|
|
286
|
+
this.handleError(redirectError);
|
|
287
|
+
return null;
|
|
231
288
|
}
|
|
232
289
|
}
|
|
233
|
-
|
|
290
|
+
this.handleError(error);
|
|
291
|
+
return null;
|
|
234
292
|
}
|
|
235
293
|
}
|
|
236
294
|
// ── Internal Helpers ──
|
|
237
|
-
selectAccount(
|
|
238
|
-
const
|
|
239
|
-
if (
|
|
240
|
-
this.updateState({ isAuthenticated:
|
|
295
|
+
selectAccount(policy) {
|
|
296
|
+
const accounts = this.msalInstance.getAllAccounts();
|
|
297
|
+
if (accounts.length === 0) {
|
|
298
|
+
this.updateState({ isAuthenticated: false, user: null });
|
|
241
299
|
return;
|
|
242
300
|
}
|
|
243
|
-
let
|
|
244
|
-
if (
|
|
245
|
-
|
|
246
|
-
else if (
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
|
|
301
|
+
let selected = null;
|
|
302
|
+
if (accounts.length === 1) {
|
|
303
|
+
selected = accounts[0];
|
|
304
|
+
} else if (policy) {
|
|
305
|
+
const filtered = accounts.filter((account) => {
|
|
306
|
+
const claims = account.idTokenClaims;
|
|
307
|
+
const iss = claims?.iss ?? "";
|
|
308
|
+
const knownAuthorities = this.provider.getKnownAuthorities();
|
|
309
|
+
const matchesAuthority = knownAuthorities.some((auth) => iss.toUpperCase().includes(auth.toUpperCase()));
|
|
310
|
+
const matchesPolicy = account.homeAccountId.toUpperCase().includes(policy.toUpperCase());
|
|
311
|
+
return matchesAuthority && matchesPolicy;
|
|
250
312
|
});
|
|
251
|
-
|
|
313
|
+
if (filtered.length >= 1) {
|
|
314
|
+
selected = filtered[0];
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (!selected && accounts.length > 0) {
|
|
318
|
+
selected = accounts[0];
|
|
319
|
+
}
|
|
320
|
+
if (selected) {
|
|
321
|
+
this.log("Account selected", selected.username);
|
|
322
|
+
this.updateState({ isAuthenticated: true, user: selected });
|
|
252
323
|
}
|
|
253
|
-
!i && e.length > 0 && (i = e[0]), i && (this.log("Account selected", i.username), this.updateState({ isAuthenticated: !0, user: i }));
|
|
254
324
|
}
|
|
255
|
-
async acquireTokenAfterRedirect(
|
|
256
|
-
const
|
|
257
|
-
|
|
325
|
+
async acquireTokenAfterRedirect(response) {
|
|
326
|
+
const account = this.msalInstance.getAccountByHomeId(response.account?.homeAccountId ?? "") ?? response.account ?? null;
|
|
327
|
+
if (account) {
|
|
328
|
+
this.updateState({ isAuthenticated: true, user: account });
|
|
329
|
+
}
|
|
330
|
+
await this.acquireToken();
|
|
331
|
+
this.updateState({ isLoading: false });
|
|
258
332
|
}
|
|
259
|
-
buildLoginRequest(
|
|
333
|
+
buildLoginRequest(authority, options) {
|
|
334
|
+
const scopes = options?.scopes ?? this.provider.getDefaultScopes();
|
|
260
335
|
return {
|
|
261
|
-
scopes
|
|
262
|
-
authority
|
|
336
|
+
scopes,
|
|
337
|
+
authority,
|
|
263
338
|
state: this.encodedState ? `${this.encodedState}` : void 0,
|
|
264
|
-
loginHint:
|
|
265
|
-
domainHint:
|
|
339
|
+
loginHint: options?.loginHint,
|
|
340
|
+
domainHint: options?.domainHint
|
|
266
341
|
};
|
|
267
342
|
}
|
|
268
|
-
isForgotPasswordPolicy(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
343
|
+
isForgotPasswordPolicy(policy) {
|
|
344
|
+
if (!policy) return false;
|
|
345
|
+
if (!(this.provider instanceof B2CProvider)) return false;
|
|
346
|
+
return policy.toUpperCase() === this.provider.getPolicies().resetPassword.toUpperCase();
|
|
347
|
+
}
|
|
348
|
+
handleRedirectError(error) {
|
|
349
|
+
const err = error;
|
|
350
|
+
if (err.errorMessage?.includes(MSAL_ERROR_CODES.FORGOT_PASSWORD)) {
|
|
351
|
+
this.log("Forgot password error detected, redirecting...");
|
|
352
|
+
this.forgotPassword();
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
this.handleError(error);
|
|
356
|
+
this.updateState({ isLoading: false });
|
|
357
|
+
return null;
|
|
273
358
|
}
|
|
274
|
-
handleError(
|
|
275
|
-
const
|
|
276
|
-
this.log("Error:",
|
|
359
|
+
handleError(error) {
|
|
360
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
361
|
+
this.log("Error:", err.message);
|
|
362
|
+
this.updateState({ error: err });
|
|
363
|
+
this.events.emit("auth:error", err);
|
|
277
364
|
}
|
|
278
|
-
updateState(
|
|
279
|
-
this._state = { ...this._state, ...
|
|
365
|
+
updateState(partial) {
|
|
366
|
+
this._state = { ...this._state, ...partial };
|
|
367
|
+
this.events.emit("auth:stateChanged", this._state);
|
|
280
368
|
}
|
|
281
369
|
assertInitialized() {
|
|
282
|
-
if (!this.msalInstance)
|
|
370
|
+
if (!this.msalInstance) {
|
|
283
371
|
throw new Error("SSOClient not initialized. Call initialize() first.");
|
|
372
|
+
}
|
|
284
373
|
}
|
|
285
|
-
log(...
|
|
286
|
-
this.debug
|
|
374
|
+
log(...args) {
|
|
375
|
+
if (this.debug) {
|
|
376
|
+
console.log("[sso-core]", ...args);
|
|
377
|
+
}
|
|
287
378
|
}
|
|
288
379
|
}
|
|
289
|
-
class
|
|
380
|
+
class CIAMProvider {
|
|
290
381
|
type = "ciam";
|
|
291
382
|
config;
|
|
292
|
-
constructor(
|
|
293
|
-
this.config =
|
|
383
|
+
constructor(config) {
|
|
384
|
+
this.config = config;
|
|
294
385
|
}
|
|
295
386
|
buildMsalConfig() {
|
|
296
387
|
return {
|
|
@@ -300,7 +391,7 @@ class C {
|
|
|
300
391
|
knownAuthorities: this.getKnownAuthorities(),
|
|
301
392
|
redirectUri: this.config.redirectUri,
|
|
302
393
|
postLogoutRedirectUri: this.config.postLogoutRedirectUri ?? this.config.redirectUri,
|
|
303
|
-
navigateToLoginRequestUrl:
|
|
394
|
+
navigateToLoginRequestUrl: false
|
|
304
395
|
},
|
|
305
396
|
cache: {
|
|
306
397
|
cacheLocation: this.config.cacheLocation ?? "sessionStorage"
|
|
@@ -313,7 +404,7 @@ class C {
|
|
|
313
404
|
getKnownAuthorities() {
|
|
314
405
|
return [`${this.config.tenantSubdomain}.ciamlogin.com`];
|
|
315
406
|
}
|
|
316
|
-
identifyPolicy(
|
|
407
|
+
identifyPolicy(_response) {
|
|
317
408
|
return null;
|
|
318
409
|
}
|
|
319
410
|
getDefaultScopes() {
|
|
@@ -323,11 +414,11 @@ class C {
|
|
|
323
414
|
return this.config.scopes ?? [];
|
|
324
415
|
}
|
|
325
416
|
}
|
|
326
|
-
class
|
|
417
|
+
class EntraProvider {
|
|
327
418
|
type = "entra";
|
|
328
419
|
config;
|
|
329
|
-
constructor(
|
|
330
|
-
this.config =
|
|
420
|
+
constructor(config) {
|
|
421
|
+
this.config = config;
|
|
331
422
|
}
|
|
332
423
|
buildMsalConfig() {
|
|
333
424
|
return {
|
|
@@ -337,7 +428,7 @@ class P {
|
|
|
337
428
|
knownAuthorities: this.getKnownAuthorities(),
|
|
338
429
|
redirectUri: this.config.redirectUri,
|
|
339
430
|
postLogoutRedirectUri: this.config.postLogoutRedirectUri ?? this.config.redirectUri,
|
|
340
|
-
navigateToLoginRequestUrl:
|
|
431
|
+
navigateToLoginRequestUrl: false
|
|
341
432
|
},
|
|
342
433
|
cache: {
|
|
343
434
|
cacheLocation: this.config.cacheLocation ?? "sessionStorage"
|
|
@@ -350,7 +441,7 @@ class P {
|
|
|
350
441
|
getKnownAuthorities() {
|
|
351
442
|
return ["login.microsoftonline.com"];
|
|
352
443
|
}
|
|
353
|
-
identifyPolicy(
|
|
444
|
+
identifyPolicy(_response) {
|
|
354
445
|
return null;
|
|
355
446
|
}
|
|
356
447
|
getDefaultScopes() {
|
|
@@ -361,18 +452,18 @@ class P {
|
|
|
361
452
|
}
|
|
362
453
|
}
|
|
363
454
|
export {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
455
|
+
B2CProvider,
|
|
456
|
+
CACHE_CONFIG,
|
|
457
|
+
CIAMProvider,
|
|
458
|
+
DEFAULT_POLICIES,
|
|
459
|
+
DEFAULT_SCOPES,
|
|
460
|
+
EntraProvider,
|
|
461
|
+
MSAL_ERROR_CODES,
|
|
462
|
+
SSOClient,
|
|
463
|
+
SSOEventEmitter,
|
|
464
|
+
STATE_SEPARATOR,
|
|
465
|
+
decodeState,
|
|
466
|
+
encodeState,
|
|
467
|
+
extractCustomState
|
|
377
468
|
};
|
|
378
469
|
//# sourceMappingURL=index.mjs.map
|