oidc-spa 8.0.4 → 8.1.0
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/angular.d.ts +191 -0
- package/angular.js +351 -0
- package/angular.js.map +1 -0
- package/core/createOidc.d.ts +7 -7
- package/core/createOidc.js +15 -2
- package/core/createOidc.js.map +1 -1
- package/core/oidcClientTsUserToTokens.js +7 -0
- package/core/oidcClientTsUserToTokens.js.map +1 -1
- package/esm/angular.d.ts +191 -0
- package/esm/angular.js +314 -0
- package/esm/angular.js.map +1 -0
- package/esm/core/createOidc.d.ts +7 -7
- package/esm/core/createOidc.js +15 -2
- package/esm/core/createOidc.js.map +1 -1
- package/esm/core/oidcClientTsUserToTokens.js +7 -0
- package/esm/core/oidcClientTsUserToTokens.js.map +1 -1
- package/esm/keycloak/keycloakUtils.js.map +1 -1
- package/esm/mock/oidc.js +2 -1
- package/esm/mock/oidc.js.map +1 -1
- package/esm/tools/ConcreteClass.d.ts +3 -0
- package/esm/tools/ConcreteClass.js +2 -0
- package/esm/tools/ConcreteClass.js.map +1 -0
- package/esm/tools/Deferred.d.ts +7 -0
- package/esm/tools/Deferred.js +5 -0
- package/esm/tools/Deferred.js.map +1 -1
- package/esm/tools/INFINITY_TIME.d.ts +1 -0
- package/esm/tools/INFINITY_TIME.js +3 -0
- package/esm/tools/INFINITY_TIME.js.map +1 -0
- package/esm/tools/ReadonlyBehaviorSubject.d.ts +8 -0
- package/esm/tools/ReadonlyBehaviorSubject.js +2 -0
- package/esm/tools/ReadonlyBehaviorSubject.js.map +1 -0
- package/esm/tools/getBaseHref.d.ts +1 -0
- package/esm/tools/getBaseHref.js +8 -0
- package/esm/tools/getBaseHref.js.map +1 -0
- package/esm/tools/readExpirationTimeInJwt.js +4 -0
- package/esm/tools/readExpirationTimeInJwt.js.map +1 -1
- package/esm/vendor/frontend/tsafe.d.ts +1 -0
- package/esm/vendor/frontend/tsafe.js +1 -1
- package/keycloak/keycloakUtils.js.map +1 -1
- package/mock/oidc.js +2 -1
- package/mock/oidc.js.map +1 -1
- package/package.json +3 -3
- package/src/angular.ts +583 -0
- package/src/core/createOidc.ts +28 -10
- package/src/core/oidcClientTsUserToTokens.ts +9 -0
- package/src/keycloak/keycloakUtils.ts +0 -1
- package/src/mock/oidc.ts +2 -1
- package/src/tools/ConcreteClass.ts +3 -0
- package/src/tools/Deferred.ts +10 -0
- package/src/tools/INFINITY_TIME.ts +2 -0
- package/src/tools/ReadonlyBehaviorSubject.ts +9 -0
- package/src/tools/getBaseHref.ts +7 -0
- package/src/tools/readExpirationTimeInJwt.ts +5 -0
- package/src/vendor/frontend/tsafe.ts +1 -0
- package/tools/ConcreteClass.d.ts +3 -0
- package/tools/ConcreteClass.js +3 -0
- package/tools/ConcreteClass.js.map +1 -0
- package/tools/Deferred.d.ts +7 -0
- package/tools/Deferred.js +5 -0
- package/tools/Deferred.js.map +1 -1
- package/tools/INFINITY_TIME.d.ts +1 -0
- package/tools/INFINITY_TIME.js +6 -0
- package/tools/INFINITY_TIME.js.map +1 -0
- package/tools/ReadonlyBehaviorSubject.d.ts +8 -0
- package/tools/ReadonlyBehaviorSubject.js +3 -0
- package/tools/ReadonlyBehaviorSubject.js.map +1 -0
- package/tools/getBaseHref.d.ts +1 -0
- package/tools/getBaseHref.js +11 -0
- package/tools/getBaseHref.js.map +1 -0
- package/tools/readExpirationTimeInJwt.js +4 -0
- package/tools/readExpirationTimeInJwt.js.map +1 -1
- package/vendor/frontend/tsafe.d.ts +1 -0
- package/vendor/frontend/tsafe.js +1 -1
- package/angular/angular.d.ts +0 -72
- package/angular/angular.js +0 -253
- package/angular/angular.js.map +0 -1
- package/angular/index.d.ts +0 -1
- package/angular/index.js +0 -6
- package/angular/index.js.map +0 -1
- package/esm/angular/angular.d.ts +0 -72
- package/esm/angular/angular.js +0 -249
- package/esm/angular/angular.js.map +0 -1
- package/esm/angular/index.d.ts +0 -1
- package/esm/angular/index.js +0 -2
- package/esm/angular/index.js.map +0 -1
- package/esm/mock/angular.d.ts +0 -41
- package/esm/mock/angular.js +0 -7
- package/esm/mock/angular.js.map +0 -1
- package/mock/angular.d.ts +0 -41
- package/mock/angular.js +0 -10
- package/mock/angular.js.map +0 -1
- package/src/angular/angular.ts +0 -428
- package/src/angular/index.ts +0 -1
- package/src/mock/angular.ts +0 -11
package/src/angular/angular.ts
DELETED
|
@@ -1,428 +0,0 @@
|
|
|
1
|
-
import { type Oidc, createOidc, type ParamsOfCreateOidc, OidcInitializationError } from "../core";
|
|
2
|
-
import { assert, type Equals } from "../vendor/frontend/tsafe";
|
|
3
|
-
import { id } from "../vendor/frontend/tsafe";
|
|
4
|
-
import type { ValueOrAsyncGetter } from "../tools/ValueOrAsyncGetter";
|
|
5
|
-
import { Deferred } from "../tools/Deferred";
|
|
6
|
-
import { type Signal, type EnvironmentProviders, provideAppInitializer, inject } from "@angular/core";
|
|
7
|
-
import { type CanActivateFn, Router } from "@angular/router";
|
|
8
|
-
import { toSignal } from "@angular/core/rxjs-interop";
|
|
9
|
-
import { BehaviorSubject } from "rxjs";
|
|
10
|
-
import { createObjectThatThrowsIfAccessed } from "../tools/createObjectThatThrowsIfAccessed";
|
|
11
|
-
|
|
12
|
-
export type OidcAngular = OidcAngular.NotLoggedIn | OidcAngular.LoggedIn;
|
|
13
|
-
|
|
14
|
-
export namespace OidcAngular {
|
|
15
|
-
export type Common = Oidc.Common;
|
|
16
|
-
|
|
17
|
-
export type NotLoggedIn = Common & {
|
|
18
|
-
isUserLoggedIn: false;
|
|
19
|
-
login: (params?: {
|
|
20
|
-
extraQueryParams?: Record<string, string | undefined>;
|
|
21
|
-
transformUrlBeforeRedirect?: (url: string) => string;
|
|
22
|
-
}) => Promise<never>;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type LoggedIn = Common & {
|
|
26
|
-
isUserLoggedIn: true;
|
|
27
|
-
logout: Oidc.LoggedIn["logout"];
|
|
28
|
-
renewTokens: Oidc.LoggedIn["renewTokens"];
|
|
29
|
-
goToAuthServer: Oidc.LoggedIn["goToAuthServer"];
|
|
30
|
-
backFromAuthServer:
|
|
31
|
-
| {
|
|
32
|
-
extraQueryParams: Record<string, string>;
|
|
33
|
-
result: Record<string, string>;
|
|
34
|
-
}
|
|
35
|
-
| undefined;
|
|
36
|
-
isNewBrowserSession: boolean;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type OidcAngularApi<DecodedIdToken extends Record<string, unknown>, AutoLogin extends boolean> = {
|
|
41
|
-
getOidc: AutoLogin extends true
|
|
42
|
-
? {
|
|
43
|
-
(params?: { assert: "user logged in" }): OidcAngular.LoggedIn;
|
|
44
|
-
}
|
|
45
|
-
: {
|
|
46
|
-
(params?: { assert?: undefined }): OidcAngular;
|
|
47
|
-
(params: { assert: "user logged in" }): OidcAngular.LoggedIn;
|
|
48
|
-
(params: { assert: "user not logged in" }): OidcAngular.NotLoggedIn;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
getOidcInitializationError: () => OidcInitializationError | undefined;
|
|
52
|
-
|
|
53
|
-
get$decodedIdToken: () => Signal<DecodedIdToken>;
|
|
54
|
-
|
|
55
|
-
get$secondsLeftBeforeAutoLogout: (params: {
|
|
56
|
-
warningDurationSeconds: number;
|
|
57
|
-
}) => Signal<number | undefined>;
|
|
58
|
-
|
|
59
|
-
getTokens: () => Promise<
|
|
60
|
-
| { isUserLoggedIn: false; prTokens?: never }
|
|
61
|
-
| { isUserLoggedIn: true; prTokens: Promise<Oidc.Tokens<DecodedIdToken>> }
|
|
62
|
-
>;
|
|
63
|
-
|
|
64
|
-
provideOidcInitAwaiter: EnvironmentProviders;
|
|
65
|
-
} & (AutoLogin extends true
|
|
66
|
-
? {}
|
|
67
|
-
: {
|
|
68
|
-
enforceLoginGuard: CanActivateFn;
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
export function createAngularOidc_dependencyInjection<
|
|
72
|
-
DecodedIdToken extends Record<string, unknown>,
|
|
73
|
-
ParamsOfCreateOidc extends {
|
|
74
|
-
autoLogin?: boolean;
|
|
75
|
-
} & (
|
|
76
|
-
| {
|
|
77
|
-
decodedIdTokenSchema: { parse: (data: unknown) => DecodedIdToken } | undefined;
|
|
78
|
-
}
|
|
79
|
-
| {}
|
|
80
|
-
)
|
|
81
|
-
>(
|
|
82
|
-
paramsOrGetParams: ValueOrAsyncGetter<ParamsOfCreateOidc>,
|
|
83
|
-
createOidc: (params: ParamsOfCreateOidc) => Promise<Oidc<DecodedIdToken>>
|
|
84
|
-
): OidcAngularApi<
|
|
85
|
-
DecodedIdToken,
|
|
86
|
-
ParamsOfCreateOidc extends { autoLogin?: true | undefined } ? true : false
|
|
87
|
-
> {
|
|
88
|
-
const dReadyToCreate = new Deferred<void>();
|
|
89
|
-
|
|
90
|
-
// NOTE: It can be InitializationError only if autoLogin is true
|
|
91
|
-
const prOidcOrAutoLoginInitializationError = (async () => {
|
|
92
|
-
const params = await (async () => {
|
|
93
|
-
await dReadyToCreate.pr;
|
|
94
|
-
|
|
95
|
-
if (typeof paramsOrGetParams === "function") {
|
|
96
|
-
const getParams = paramsOrGetParams;
|
|
97
|
-
|
|
98
|
-
const params = await getParams();
|
|
99
|
-
|
|
100
|
-
return params;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const params = paramsOrGetParams;
|
|
104
|
-
|
|
105
|
-
return params;
|
|
106
|
-
})();
|
|
107
|
-
|
|
108
|
-
let oidc: Oidc<DecodedIdToken>;
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
oidc = await createOidc(params);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
if (!(error instanceof OidcInitializationError)) {
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return error;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return oidc;
|
|
121
|
-
})();
|
|
122
|
-
|
|
123
|
-
let oidcOrAutoLoginInitializationError: Oidc<DecodedIdToken> | OidcInitializationError | undefined =
|
|
124
|
-
undefined;
|
|
125
|
-
|
|
126
|
-
prOidcOrAutoLoginInitializationError.then(value => {
|
|
127
|
-
oidcOrAutoLoginInitializationError = value;
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
function getOidc(params?: { assert?: "user logged in" | "user not logged in" }): OidcAngular {
|
|
131
|
-
const { assert: assert_params } = params ?? {};
|
|
132
|
-
|
|
133
|
-
if (oidcOrAutoLoginInitializationError === undefined) {
|
|
134
|
-
throw new Error("oidc-spa: calling getOidc() before provideOidcInitAwaiter has resolved");
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (oidcOrAutoLoginInitializationError instanceof OidcInitializationError) {
|
|
138
|
-
throw new Error(
|
|
139
|
-
"oidc-spa: calling getOidc() while getOidcInitializationError() is not `undefined` in autoLogin: true mode"
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const oidc = oidcOrAutoLoginInitializationError;
|
|
144
|
-
|
|
145
|
-
check_assertion: {
|
|
146
|
-
if (assert_params === undefined) {
|
|
147
|
-
break check_assertion;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const getMessage = (v: string) =>
|
|
151
|
-
[
|
|
152
|
-
"There is a logic error in the application.",
|
|
153
|
-
`If this component is mounted the user is supposed ${v}.`,
|
|
154
|
-
"An explicit assertion was made in this sense."
|
|
155
|
-
].join(" ");
|
|
156
|
-
|
|
157
|
-
switch (assert_params) {
|
|
158
|
-
case "user logged in":
|
|
159
|
-
if (!oidc.isUserLoggedIn) {
|
|
160
|
-
throw new Error(getMessage("to be logged in but currently they arn't"));
|
|
161
|
-
}
|
|
162
|
-
break;
|
|
163
|
-
case "user not logged in":
|
|
164
|
-
if (oidc.isUserLoggedIn) {
|
|
165
|
-
throw new Error(getMessage("not to be logged in but currently they are"));
|
|
166
|
-
}
|
|
167
|
-
break;
|
|
168
|
-
default:
|
|
169
|
-
assert<Equals<typeof assert_params, never>>(false);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const common: OidcAngular.Common = {
|
|
174
|
-
params: oidc.params
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
return oidc.isUserLoggedIn
|
|
178
|
-
? id<OidcAngular.LoggedIn>({
|
|
179
|
-
...common,
|
|
180
|
-
isUserLoggedIn: true,
|
|
181
|
-
logout: oidc.logout,
|
|
182
|
-
renewTokens: oidc.renewTokens,
|
|
183
|
-
goToAuthServer: oidc.goToAuthServer,
|
|
184
|
-
backFromAuthServer: oidc.backFromAuthServer,
|
|
185
|
-
isNewBrowserSession: oidc.isNewBrowserSession
|
|
186
|
-
})
|
|
187
|
-
: id<OidcAngular.NotLoggedIn>({
|
|
188
|
-
...common,
|
|
189
|
-
isUserLoggedIn: false,
|
|
190
|
-
login: params =>
|
|
191
|
-
oidc.login({
|
|
192
|
-
...params,
|
|
193
|
-
doesCurrentHrefRequiresAuth: false
|
|
194
|
-
})
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function getOidcInitializationError(): OidcInitializationError | undefined {
|
|
199
|
-
if (oidcOrAutoLoginInitializationError === undefined) {
|
|
200
|
-
throw new Error(
|
|
201
|
-
"oidc-spa: calling getOidcInitializationError() before provideOidcInitAwaiter has resolved"
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (oidcOrAutoLoginInitializationError instanceof OidcInitializationError) {
|
|
206
|
-
return oidcOrAutoLoginInitializationError;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const oidc = oidcOrAutoLoginInitializationError;
|
|
210
|
-
|
|
211
|
-
if (!oidc.isUserLoggedIn && oidc.initializationError !== undefined) {
|
|
212
|
-
return oidc.initializationError;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return undefined;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const { get$decodedIdToken } = (() => {
|
|
219
|
-
function createDecodedIdToken$() {
|
|
220
|
-
if (oidcOrAutoLoginInitializationError === undefined) {
|
|
221
|
-
throw new Error(
|
|
222
|
-
"oidc-spa: calling get$decodedIdToken() before provideOidcInitAwaiter has resolved"
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (oidcOrAutoLoginInitializationError instanceof OidcInitializationError) {
|
|
227
|
-
throw new Error(
|
|
228
|
-
"oidc-spa: calling getOidc() while getOidcInitializationError() is not `undefined` in autoLogin: true mode"
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const oidc = oidcOrAutoLoginInitializationError;
|
|
233
|
-
|
|
234
|
-
let initialValue: DecodedIdToken;
|
|
235
|
-
|
|
236
|
-
if (!oidc.isUserLoggedIn) {
|
|
237
|
-
initialValue = createObjectThatThrowsIfAccessed({
|
|
238
|
-
debugMessage: [
|
|
239
|
-
"You are trying to read the decodedIdToken but the user",
|
|
240
|
-
"isn't logged in"
|
|
241
|
-
].join(" ")
|
|
242
|
-
});
|
|
243
|
-
} else {
|
|
244
|
-
initialValue = oidc.getDecodedIdToken();
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const decodedIdToken$ = new BehaviorSubject<DecodedIdToken>(initialValue);
|
|
248
|
-
|
|
249
|
-
if (oidc.isUserLoggedIn) {
|
|
250
|
-
oidc.subscribeToTokensChange(() => {
|
|
251
|
-
const decodedIdToken = oidc.getDecodedIdToken();
|
|
252
|
-
|
|
253
|
-
if (decodedIdToken$.getValue() === decodedIdToken) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
decodedIdToken$.next(decodedIdToken);
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return decodedIdToken$;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
let decodedIdToken$: BehaviorSubject<DecodedIdToken> | undefined = undefined;
|
|
265
|
-
|
|
266
|
-
function get$decodedIdToken(): Signal<DecodedIdToken> {
|
|
267
|
-
return toSignal((decodedIdToken$ ??= createDecodedIdToken$()), {
|
|
268
|
-
requireSync: true
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return { get$decodedIdToken };
|
|
273
|
-
})();
|
|
274
|
-
|
|
275
|
-
const { get$secondsLeftBeforeAutoLogout } = (() => {
|
|
276
|
-
function createSecondsLeftBeforeAutoLogout$() {
|
|
277
|
-
if (oidcOrAutoLoginInitializationError === undefined) {
|
|
278
|
-
throw new Error(
|
|
279
|
-
"oidc-spa: calling get$decodedIdToken() before provideOidcInitAwaiter has resolved"
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (oidcOrAutoLoginInitializationError instanceof OidcInitializationError) {
|
|
284
|
-
throw new Error(
|
|
285
|
-
"oidc-spa: calling getOidc() while getOidcInitializationError() is not `undefined` in autoLogin: true mode"
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const oidc = oidcOrAutoLoginInitializationError;
|
|
290
|
-
|
|
291
|
-
const secondsLeftBeforeAutoLogout$ = new BehaviorSubject<number | undefined>(undefined);
|
|
292
|
-
|
|
293
|
-
if (oidc.isUserLoggedIn) {
|
|
294
|
-
oidc.subscribeToAutoLogoutCountdown(({ secondsLeft }) =>
|
|
295
|
-
secondsLeftBeforeAutoLogout$.next(secondsLeft)
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return secondsLeftBeforeAutoLogout$;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
let secondsLeftBeforeAutoLogout$: BehaviorSubject<number | undefined> | undefined = undefined;
|
|
303
|
-
|
|
304
|
-
function get$secondsLeftBeforeAutoLogout(params: {
|
|
305
|
-
warningDurationSeconds: number;
|
|
306
|
-
}): Signal<number | undefined> {
|
|
307
|
-
const { warningDurationSeconds } = params;
|
|
308
|
-
|
|
309
|
-
secondsLeftBeforeAutoLogout$ ??= createSecondsLeftBeforeAutoLogout$();
|
|
310
|
-
|
|
311
|
-
const secondsLeftBeforeAutoLogout$_cropped = new BehaviorSubject<number | undefined>(
|
|
312
|
-
secondsLeftBeforeAutoLogout$.getValue()
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
secondsLeftBeforeAutoLogout$.subscribe(secondsLeftBeforeAutoLogout => {
|
|
316
|
-
if (
|
|
317
|
-
secondsLeftBeforeAutoLogout === undefined ||
|
|
318
|
-
secondsLeftBeforeAutoLogout > warningDurationSeconds
|
|
319
|
-
) {
|
|
320
|
-
if (secondsLeftBeforeAutoLogout$_cropped.getValue() !== undefined) {
|
|
321
|
-
secondsLeftBeforeAutoLogout$_cropped.next(undefined);
|
|
322
|
-
}
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
secondsLeftBeforeAutoLogout$_cropped.next(secondsLeftBeforeAutoLogout);
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
const signal = toSignal(secondsLeftBeforeAutoLogout$_cropped, {
|
|
330
|
-
requireSync: true
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
return signal;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return { get$secondsLeftBeforeAutoLogout };
|
|
337
|
-
})();
|
|
338
|
-
|
|
339
|
-
async function getTokens(): Promise<
|
|
340
|
-
| { isUserLoggedIn: false; prTokens?: never }
|
|
341
|
-
| { isUserLoggedIn: true; prTokens: Promise<Oidc.Tokens<DecodedIdToken>> }
|
|
342
|
-
> {
|
|
343
|
-
const oidcOrAutoLoginInitializationError = await prOidcOrAutoLoginInitializationError;
|
|
344
|
-
|
|
345
|
-
if (oidcOrAutoLoginInitializationError instanceof OidcInitializationError) {
|
|
346
|
-
return new Promise<never>(() => {});
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const oidc = oidcOrAutoLoginInitializationError;
|
|
350
|
-
|
|
351
|
-
return oidc.isUserLoggedIn
|
|
352
|
-
? { isUserLoggedIn: true, prTokens: oidc.getTokens() }
|
|
353
|
-
: {
|
|
354
|
-
isUserLoggedIn: false
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
const provideOidcInitAwaiter: EnvironmentProviders = provideAppInitializer(async () => {
|
|
359
|
-
dReadyToCreate.resolve();
|
|
360
|
-
await prOidcOrAutoLoginInitializationError;
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
const enforceLoginGuard: CanActivateFn = async route => {
|
|
364
|
-
const router = inject(Router);
|
|
365
|
-
|
|
366
|
-
const oidcOrAutoLoginInitializationError = await prOidcOrAutoLoginInitializationError;
|
|
367
|
-
|
|
368
|
-
if (oidcOrAutoLoginInitializationError instanceof OidcInitializationError) {
|
|
369
|
-
return new Promise<never>(() => {});
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
const oidc = oidcOrAutoLoginInitializationError;
|
|
373
|
-
|
|
374
|
-
if (!oidc.isUserLoggedIn) {
|
|
375
|
-
const redirectUrl = (() => {
|
|
376
|
-
const tree = router.createUrlTree(
|
|
377
|
-
route.url.map(u => u.path),
|
|
378
|
-
{
|
|
379
|
-
queryParams: route.queryParams
|
|
380
|
-
}
|
|
381
|
-
);
|
|
382
|
-
return router.serializeUrl(tree);
|
|
383
|
-
})();
|
|
384
|
-
|
|
385
|
-
const doesCurrentHrefRequiresAuth =
|
|
386
|
-
location.href.replace(/\/$/, "") === redirectUrl.replace(/\/$/, "");
|
|
387
|
-
|
|
388
|
-
await oidc.login({
|
|
389
|
-
doesCurrentHrefRequiresAuth,
|
|
390
|
-
redirectUrl
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
return true;
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
const oidcAngularApi = id<OidcAngularApi<DecodedIdToken, false>>({
|
|
398
|
-
getOidc: getOidc as any,
|
|
399
|
-
getOidcInitializationError,
|
|
400
|
-
get$decodedIdToken,
|
|
401
|
-
get$secondsLeftBeforeAutoLogout,
|
|
402
|
-
getTokens,
|
|
403
|
-
provideOidcInitAwaiter,
|
|
404
|
-
enforceLoginGuard
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
// @ts-expect-error: We know what we are doing
|
|
408
|
-
return oidcAngularApi;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/** @see: https://docs.oidc-spa.dev/v/v8/usage#angular-api */
|
|
412
|
-
export function createAngularOidc<
|
|
413
|
-
DecodedIdToken extends Record<string, unknown> = Oidc.Tokens.DecodedIdToken_base,
|
|
414
|
-
AutoLogin extends boolean = false
|
|
415
|
-
>(params: ValueOrAsyncGetter<Omit<ParamsOfCreateOidc<DecodedIdToken, AutoLogin>, "homeUrl">>) {
|
|
416
|
-
return createAngularOidc_dependencyInjection(params, params =>
|
|
417
|
-
createOidc({
|
|
418
|
-
...params,
|
|
419
|
-
homeUrl: (() => {
|
|
420
|
-
const baseEl = document.querySelector<HTMLBaseElement>("base[href]");
|
|
421
|
-
if (!baseEl) {
|
|
422
|
-
throw new Error('No <base href="..."> element found in the DOM');
|
|
423
|
-
}
|
|
424
|
-
return baseEl.getAttribute("href") ?? "/";
|
|
425
|
-
})()
|
|
426
|
-
})
|
|
427
|
-
);
|
|
428
|
-
}
|
package/src/angular/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { type OidcAngular, createAngularOidc } from "./angular";
|
package/src/mock/angular.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createAngularOidc_dependencyInjection } from "../angular/angular";
|
|
2
|
-
import { createMockOidc, type ParamsOfCreateMockOidc } from "./oidc";
|
|
3
|
-
import type { ValueOrAsyncGetter } from "../tools/ValueOrAsyncGetter";
|
|
4
|
-
|
|
5
|
-
/** @see: https://docs.oidc-spa.dev/v/v8/mock */
|
|
6
|
-
export function createMockAngularOidc<
|
|
7
|
-
DecodedIdToken extends Record<string, unknown> = Record<string, unknown>,
|
|
8
|
-
AutoLogin extends boolean = false
|
|
9
|
-
>(params: ValueOrAsyncGetter<ParamsOfCreateMockOidc<DecodedIdToken, AutoLogin>>) {
|
|
10
|
-
return createAngularOidc_dependencyInjection(params, createMockOidc);
|
|
11
|
-
}
|