@dangl/angular-dangl-identity-client 6.2.0 → 6.3.0-beta0021

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.
Files changed (29) hide show
  1. package/README.md +25 -0
  2. package/api-client.d.ts +178 -178
  3. package/dangl-identity.module.d.ts +6 -7
  4. package/{fesm2020 → fesm2022}/dangl-angular-dangl-identity-client.mjs +905 -873
  5. package/fesm2022/dangl-angular-dangl-identity-client.mjs.map +1 -0
  6. package/index.d.ts +5 -5
  7. package/interceptors/dangl-identity-request-validator.d.ts +4 -4
  8. package/interceptors/jwt-interceptor.service.d.ts +16 -16
  9. package/messengers/authentication.messenger.d.ts +28 -26
  10. package/models/jwt-storage.d.ts +5 -5
  11. package/models/user-info.d.ts +11 -11
  12. package/package.json +5 -13
  13. package/public_api.d.ts +8 -8
  14. package/services/authentication.service.d.ts +14 -14
  15. package/services/jwt-token.service.d.ts +28 -28
  16. package/esm2020/api-client.mjs +0 -551
  17. package/esm2020/dangl-angular-dangl-identity-client.mjs +0 -5
  18. package/esm2020/dangl-identity.module.mjs +0 -29
  19. package/esm2020/interceptors/dangl-identity-request-validator.mjs +0 -2
  20. package/esm2020/interceptors/jwt-interceptor.service.mjs +0 -47
  21. package/esm2020/messengers/authentication.messenger.mjs +0 -146
  22. package/esm2020/models/jwt-storage.mjs +0 -2
  23. package/esm2020/models/user-info.mjs +0 -2
  24. package/esm2020/public_api.mjs +0 -12
  25. package/esm2020/services/authentication.service.mjs +0 -39
  26. package/esm2020/services/jwt-token.service.mjs +0 -101
  27. package/fesm2015/dangl-angular-dangl-identity-client.mjs +0 -896
  28. package/fesm2015/dangl-angular-dangl-identity-client.mjs.map +0 -1
  29. package/fesm2020/dangl-angular-dangl-identity-client.mjs.map +0 -1
@@ -1,891 +1,923 @@
1
1
  import * as i1 from '@angular/common/http';
2
- import { HttpHeaders, HttpResponseBase, HttpResponse, HttpClient, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
2
+ import { HttpHeaders, HttpResponseBase, HttpResponse, HttpClient, provideHttpClient, withInterceptorsFromDi, HTTP_INTERCEPTORS } from '@angular/common/http';
3
3
  import * as i0 from '@angular/core';
4
- import { InjectionToken, Injectable, Inject, Optional, NgModule } from '@angular/core';
4
+ import { InjectionToken, Injectable, Inject, Optional, NgModule, inject } from '@angular/core';
5
5
  import { mergeMap, catchError, first, tap, map, takeUntil } from 'rxjs/operators';
6
- import { throwError, Observable, of, Subject, ReplaySubject } from 'rxjs';
6
+ import { throwError, of, Observable, Subject, ReplaySubject, timer } from 'rxjs';
7
7
  import { JwtHelperService } from '@auth0/angular-jwt';
8
8
 
9
- //----------------------
10
- const DANGL_IDENTITY_CLIENT_API_BASE_URL = new InjectionToken('DANGL_IDENTITY_CLIENT_API_BASE_URL');
11
- class DanglIdentityClient {
12
- constructor(http, baseUrl) {
13
- this.jsonParseReviver = undefined;
14
- this.http = http;
15
- this.baseUrl = baseUrl ?? "";
16
- }
17
- loginWithCookie(model, redirectUrl) {
18
- let url_ = this.baseUrl + "/identity/login?";
19
- if (redirectUrl !== undefined && redirectUrl !== null)
20
- url_ += "redirectUrl=" + encodeURIComponent("" + redirectUrl) + "&";
21
- url_ = url_.replace(/[?&]$/, "");
22
- const content_ = JSON.stringify(model);
23
- let options_ = {
24
- body: content_,
25
- observe: "response",
26
- responseType: "blob",
27
- headers: new HttpHeaders({
28
- "Content-Type": "application/json",
29
- })
30
- };
31
- return this.http.request("post", url_, options_).pipe(mergeMap((response_) => {
32
- return this.processLoginWithCookie(response_);
33
- })).pipe(catchError((response_) => {
34
- if (response_ instanceof HttpResponseBase) {
35
- try {
36
- return this.processLoginWithCookie(response_);
37
- }
38
- catch (e) {
39
- return throwError(e);
40
- }
41
- }
42
- else
43
- return throwError(response_);
44
- }));
45
- }
46
- processLoginWithCookie(response) {
47
- const status = response.status;
48
- const responseBlob = response instanceof HttpResponse ? response.body :
49
- response.error instanceof Blob ? response.error : undefined;
50
- let _headers = {};
51
- if (response.headers) {
52
- for (let key of response.headers.keys()) {
53
- _headers[key] = response.headers.get(key);
54
- }
55
- }
56
- if (status === 204) {
57
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
58
- return of(null);
59
- }));
60
- }
61
- else if (status === 401) {
62
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
63
- return throwException("A server side error occurred.", status, _responseText, _headers);
64
- }));
65
- }
66
- else if (status !== 200 && status !== 204) {
67
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
68
- return throwException("An unexpected server error occurred.", status, _responseText, _headers);
69
- }));
70
- }
71
- return of(null);
72
- }
73
- signOutWithSignInManager() {
74
- let url_ = this.baseUrl + "/identity/login";
75
- url_ = url_.replace(/[?&]$/, "");
76
- let options_ = {
77
- observe: "response",
78
- responseType: "blob",
79
- headers: new HttpHeaders({})
80
- };
81
- return this.http.request("delete", url_, options_).pipe(mergeMap((response_) => {
82
- return this.processSignOutWithSignInManager(response_);
83
- })).pipe(catchError((response_) => {
84
- if (response_ instanceof HttpResponseBase) {
85
- try {
86
- return this.processSignOutWithSignInManager(response_);
87
- }
88
- catch (e) {
89
- return throwError(e);
90
- }
91
- }
92
- else
93
- return throwError(response_);
94
- }));
95
- }
96
- processSignOutWithSignInManager(response) {
97
- const status = response.status;
98
- const responseBlob = response instanceof HttpResponse ? response.body :
99
- response.error instanceof Blob ? response.error : undefined;
100
- let _headers = {};
101
- if (response.headers) {
102
- for (let key of response.headers.keys()) {
103
- _headers[key] = response.headers.get(key);
104
- }
105
- }
106
- if (status === 204) {
107
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
108
- return of(null);
109
- }));
110
- }
111
- else if (status !== 200 && status !== 204) {
112
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
113
- return throwException("An unexpected server error occurred.", status, _responseText, _headers);
114
- }));
115
- }
116
- return of(null);
117
- }
118
- loginAndReturnToken(model) {
119
- let url_ = this.baseUrl + "/identity/token-login";
120
- url_ = url_.replace(/[?&]$/, "");
121
- const content_ = JSON.stringify(model);
122
- let options_ = {
123
- body: content_,
124
- observe: "response",
125
- responseType: "blob",
126
- headers: new HttpHeaders({
127
- "Content-Type": "application/json",
128
- "Accept": "application/json"
129
- })
130
- };
131
- return this.http.request("post", url_, options_).pipe(mergeMap((response_) => {
132
- return this.processLoginAndReturnToken(response_);
133
- })).pipe(catchError((response_) => {
134
- if (response_ instanceof HttpResponseBase) {
135
- try {
136
- return this.processLoginAndReturnToken(response_);
137
- }
138
- catch (e) {
139
- return throwError(e);
140
- }
141
- }
142
- else
143
- return throwError(response_);
144
- }));
145
- }
146
- processLoginAndReturnToken(response) {
147
- const status = response.status;
148
- const responseBlob = response instanceof HttpResponse ? response.body :
149
- response.error instanceof Blob ? response.error : undefined;
150
- let _headers = {};
151
- if (response.headers) {
152
- for (let key of response.headers.keys()) {
153
- _headers[key] = response.headers.get(key);
154
- }
155
- }
156
- if (status === 200) {
157
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
158
- let result200 = null;
159
- result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
160
- return of(result200);
161
- }));
162
- }
163
- else if (status === 400) {
164
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
165
- let result400 = null;
166
- result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
167
- return throwException("A server side error occurred.", status, _responseText, _headers, result400);
168
- }));
169
- }
170
- else if (status === 401) {
171
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
172
- return throwException("A server side error occurred.", status, _responseText, _headers);
173
- }));
174
- }
175
- else if (status !== 200 && status !== 204) {
176
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
177
- return throwException("An unexpected server error occurred.", status, _responseText, _headers);
178
- }));
179
- }
180
- return of(null);
181
- }
182
- refreshToken(model) {
183
- let url_ = this.baseUrl + "/identity/token-refresh";
184
- url_ = url_.replace(/[?&]$/, "");
185
- const content_ = JSON.stringify(model);
186
- let options_ = {
187
- body: content_,
188
- observe: "response",
189
- responseType: "blob",
190
- headers: new HttpHeaders({
191
- "Content-Type": "application/json",
192
- "Accept": "application/json"
193
- })
194
- };
195
- return this.http.request("post", url_, options_).pipe(mergeMap((response_) => {
196
- return this.processRefreshToken(response_);
197
- })).pipe(catchError((response_) => {
198
- if (response_ instanceof HttpResponseBase) {
199
- try {
200
- return this.processRefreshToken(response_);
201
- }
202
- catch (e) {
203
- return throwError(e);
204
- }
205
- }
206
- else
207
- return throwError(response_);
208
- }));
209
- }
210
- processRefreshToken(response) {
211
- const status = response.status;
212
- const responseBlob = response instanceof HttpResponse ? response.body :
213
- response.error instanceof Blob ? response.error : undefined;
214
- let _headers = {};
215
- if (response.headers) {
216
- for (let key of response.headers.keys()) {
217
- _headers[key] = response.headers.get(key);
218
- }
219
- }
220
- if (status === 200) {
221
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
222
- let result200 = null;
223
- result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
224
- return of(result200);
225
- }));
226
- }
227
- else if (status === 400) {
228
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
229
- let result400 = null;
230
- result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
231
- return throwException("A server side error occurred.", status, _responseText, _headers, result400);
232
- }));
233
- }
234
- else if (status === 401) {
235
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
236
- return throwException("A server side error occurred.", status, _responseText, _headers);
237
- }));
238
- }
239
- else if (status !== 200 && status !== 204) {
240
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
241
- return throwException("An unexpected server error occurred.", status, _responseText, _headers);
242
- }));
243
- }
244
- return of(null);
245
- }
246
- register(registerModel) {
247
- let url_ = this.baseUrl + "/identity/register";
248
- url_ = url_.replace(/[?&]$/, "");
249
- const content_ = JSON.stringify(registerModel);
250
- let options_ = {
251
- body: content_,
252
- observe: "response",
253
- responseType: "blob",
254
- headers: new HttpHeaders({
255
- "Content-Type": "application/json",
256
- })
257
- };
258
- return this.http.request("post", url_, options_).pipe(mergeMap((response_) => {
259
- return this.processRegister(response_);
260
- })).pipe(catchError((response_) => {
261
- if (response_ instanceof HttpResponseBase) {
262
- try {
263
- return this.processRegister(response_);
264
- }
265
- catch (e) {
266
- return throwError(e);
267
- }
268
- }
269
- else
270
- return throwError(response_);
271
- }));
272
- }
273
- processRegister(response) {
274
- const status = response.status;
275
- const responseBlob = response instanceof HttpResponse ? response.body :
276
- response.error instanceof Blob ? response.error : undefined;
277
- let _headers = {};
278
- if (response.headers) {
279
- for (let key of response.headers.keys()) {
280
- _headers[key] = response.headers.get(key);
281
- }
282
- }
283
- if (status === 204) {
284
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
285
- return of(null);
286
- }));
287
- }
288
- else if (status === 400) {
289
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
290
- let result400 = null;
291
- result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
292
- return throwException("A server side error occurred.", status, _responseText, _headers, result400);
293
- }));
294
- }
295
- else if (status !== 200 && status !== 204) {
296
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
297
- return throwException("An unexpected server error occurred.", status, _responseText, _headers);
298
- }));
299
- }
300
- return of(null);
301
- }
302
- requestPasswordReset(forgotPasswordModel) {
303
- let url_ = this.baseUrl + "/identity/password-forgotten";
304
- url_ = url_.replace(/[?&]$/, "");
305
- const content_ = JSON.stringify(forgotPasswordModel);
306
- let options_ = {
307
- body: content_,
308
- observe: "response",
309
- responseType: "blob",
310
- headers: new HttpHeaders({
311
- "Content-Type": "application/json",
312
- })
313
- };
314
- return this.http.request("post", url_, options_).pipe(mergeMap((response_) => {
315
- return this.processRequestPasswordReset(response_);
316
- })).pipe(catchError((response_) => {
317
- if (response_ instanceof HttpResponseBase) {
318
- try {
319
- return this.processRequestPasswordReset(response_);
320
- }
321
- catch (e) {
322
- return throwError(e);
323
- }
324
- }
325
- else
326
- return throwError(response_);
327
- }));
328
- }
329
- processRequestPasswordReset(response) {
330
- const status = response.status;
331
- const responseBlob = response instanceof HttpResponse ? response.body :
332
- response.error instanceof Blob ? response.error : undefined;
333
- let _headers = {};
334
- if (response.headers) {
335
- for (let key of response.headers.keys()) {
336
- _headers[key] = response.headers.get(key);
337
- }
338
- }
339
- if (status === 204) {
340
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
341
- return of(null);
342
- }));
343
- }
344
- else if (status === 400) {
345
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
346
- let result400 = null;
347
- result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
348
- return throwException("A server side error occurred.", status, _responseText, _headers, result400);
349
- }));
350
- }
351
- else if (status !== 200 && status !== 204) {
352
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
353
- return throwException("An unexpected server error occurred.", status, _responseText, _headers);
354
- }));
355
- }
356
- return of(null);
357
- }
358
- getUserInfo() {
359
- let url_ = this.baseUrl + "/identity/user-info";
360
- url_ = url_.replace(/[?&]$/, "");
361
- let options_ = {
362
- observe: "response",
363
- responseType: "blob",
364
- headers: new HttpHeaders({
365
- "Accept": "application/json"
366
- })
367
- };
368
- return this.http.request("get", url_, options_).pipe(mergeMap((response_) => {
369
- return this.processGetUserInfo(response_);
370
- })).pipe(catchError((response_) => {
371
- if (response_ instanceof HttpResponseBase) {
372
- try {
373
- return this.processGetUserInfo(response_);
374
- }
375
- catch (e) {
376
- return throwError(e);
377
- }
378
- }
379
- else
380
- return throwError(response_);
381
- }));
382
- }
383
- processGetUserInfo(response) {
384
- const status = response.status;
385
- const responseBlob = response instanceof HttpResponse ? response.body :
386
- response.error instanceof Blob ? response.error : undefined;
387
- let _headers = {};
388
- if (response.headers) {
389
- for (let key of response.headers.keys()) {
390
- _headers[key] = response.headers.get(key);
391
- }
392
- }
393
- if (status === 200) {
394
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
395
- let result200 = null;
396
- result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
397
- return of(result200);
398
- }));
399
- }
400
- else if (status === 400) {
401
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
402
- let result400 = null;
403
- result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
404
- return throwException("A server side error occurred.", status, _responseText, _headers, result400);
405
- }));
406
- }
407
- else if (status !== 200 && status !== 204) {
408
- return blobToText(responseBlob).pipe(mergeMap(_responseText => {
409
- return throwException("An unexpected server error occurred.", status, _responseText, _headers);
410
- }));
411
- }
412
- return of(null);
413
- }
414
- }
415
- DanglIdentityClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: DanglIdentityClient, deps: [{ token: HttpClient }, { token: DANGL_IDENTITY_CLIENT_API_BASE_URL, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
416
- DanglIdentityClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: DanglIdentityClient, providedIn: 'root' });
417
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: DanglIdentityClient, decorators: [{
418
- type: Injectable,
419
- args: [{
420
- providedIn: 'root'
421
- }]
422
- }], ctorParameters: function () { return [{ type: i1.HttpClient, decorators: [{
423
- type: Inject,
424
- args: [HttpClient]
425
- }] }, { type: undefined, decorators: [{
426
- type: Optional
427
- }, {
428
- type: Inject,
429
- args: [DANGL_IDENTITY_CLIENT_API_BASE_URL]
430
- }] }]; } });
431
- var HttpStatusCode;
432
- (function (HttpStatusCode) {
433
- HttpStatusCode["Continue"] = "Continue";
434
- HttpStatusCode["SwitchingProtocols"] = "SwitchingProtocols";
435
- HttpStatusCode["Processing"] = "Processing";
436
- HttpStatusCode["EarlyHints"] = "EarlyHints";
437
- HttpStatusCode["OK"] = "OK";
438
- HttpStatusCode["Created"] = "Created";
439
- HttpStatusCode["Accepted"] = "Accepted";
440
- HttpStatusCode["NonAuthoritativeInformation"] = "NonAuthoritativeInformation";
441
- HttpStatusCode["NoContent"] = "NoContent";
442
- HttpStatusCode["ResetContent"] = "ResetContent";
443
- HttpStatusCode["PartialContent"] = "PartialContent";
444
- HttpStatusCode["MultiStatus"] = "MultiStatus";
445
- HttpStatusCode["AlreadyReported"] = "AlreadyReported";
446
- HttpStatusCode["IMUsed"] = "IMUsed";
447
- HttpStatusCode["MultipleChoices"] = "MultipleChoices";
448
- HttpStatusCode["Ambiguous"] = "MultipleChoices";
449
- HttpStatusCode["MovedPermanently"] = "MovedPermanently";
450
- HttpStatusCode["Moved"] = "MovedPermanently";
451
- HttpStatusCode["Found"] = "Found";
452
- HttpStatusCode["Redirect"] = "Found";
453
- HttpStatusCode["SeeOther"] = "SeeOther";
454
- HttpStatusCode["RedirectMethod"] = "SeeOther";
455
- HttpStatusCode["NotModified"] = "NotModified";
456
- HttpStatusCode["UseProxy"] = "UseProxy";
457
- HttpStatusCode["Unused"] = "Unused";
458
- HttpStatusCode["TemporaryRedirect"] = "TemporaryRedirect";
459
- HttpStatusCode["RedirectKeepVerb"] = "TemporaryRedirect";
460
- HttpStatusCode["PermanentRedirect"] = "PermanentRedirect";
461
- HttpStatusCode["BadRequest"] = "BadRequest";
462
- HttpStatusCode["Unauthorized"] = "Unauthorized";
463
- HttpStatusCode["PaymentRequired"] = "PaymentRequired";
464
- HttpStatusCode["Forbidden"] = "Forbidden";
465
- HttpStatusCode["NotFound"] = "NotFound";
466
- HttpStatusCode["MethodNotAllowed"] = "MethodNotAllowed";
467
- HttpStatusCode["NotAcceptable"] = "NotAcceptable";
468
- HttpStatusCode["ProxyAuthenticationRequired"] = "ProxyAuthenticationRequired";
469
- HttpStatusCode["RequestTimeout"] = "RequestTimeout";
470
- HttpStatusCode["Conflict"] = "Conflict";
471
- HttpStatusCode["Gone"] = "Gone";
472
- HttpStatusCode["LengthRequired"] = "LengthRequired";
473
- HttpStatusCode["PreconditionFailed"] = "PreconditionFailed";
474
- HttpStatusCode["RequestEntityTooLarge"] = "RequestEntityTooLarge";
475
- HttpStatusCode["RequestUriTooLong"] = "RequestUriTooLong";
476
- HttpStatusCode["UnsupportedMediaType"] = "UnsupportedMediaType";
477
- HttpStatusCode["RequestedRangeNotSatisfiable"] = "RequestedRangeNotSatisfiable";
478
- HttpStatusCode["ExpectationFailed"] = "ExpectationFailed";
479
- HttpStatusCode["MisdirectedRequest"] = "MisdirectedRequest";
480
- HttpStatusCode["UnprocessableEntity"] = "UnprocessableEntity";
481
- HttpStatusCode["UnprocessableContent"] = "UnprocessableEntity";
482
- HttpStatusCode["Locked"] = "Locked";
483
- HttpStatusCode["FailedDependency"] = "FailedDependency";
484
- HttpStatusCode["UpgradeRequired"] = "UpgradeRequired";
485
- HttpStatusCode["PreconditionRequired"] = "PreconditionRequired";
486
- HttpStatusCode["TooManyRequests"] = "TooManyRequests";
487
- HttpStatusCode["RequestHeaderFieldsTooLarge"] = "RequestHeaderFieldsTooLarge";
488
- HttpStatusCode["UnavailableForLegalReasons"] = "UnavailableForLegalReasons";
489
- HttpStatusCode["InternalServerError"] = "InternalServerError";
490
- HttpStatusCode["NotImplemented"] = "NotImplemented";
491
- HttpStatusCode["BadGateway"] = "BadGateway";
492
- HttpStatusCode["ServiceUnavailable"] = "ServiceUnavailable";
493
- HttpStatusCode["GatewayTimeout"] = "GatewayTimeout";
494
- HttpStatusCode["HttpVersionNotSupported"] = "HttpVersionNotSupported";
495
- HttpStatusCode["VariantAlsoNegotiates"] = "VariantAlsoNegotiates";
496
- HttpStatusCode["InsufficientStorage"] = "InsufficientStorage";
497
- HttpStatusCode["LoopDetected"] = "LoopDetected";
498
- HttpStatusCode["NotExtended"] = "NotExtended";
499
- HttpStatusCode["NetworkAuthenticationRequired"] = "NetworkAuthenticationRequired";
500
- })(HttpStatusCode || (HttpStatusCode = {}));
501
- /** Various reasons for a protocol endpoint error */
502
- var ResponseErrorType;
503
- (function (ResponseErrorType) {
504
- ResponseErrorType["None"] = "None";
505
- ResponseErrorType["Protocol"] = "Protocol";
506
- ResponseErrorType["Http"] = "Http";
507
- ResponseErrorType["Exception"] = "Exception";
508
- ResponseErrorType["PolicyViolation"] = "PolicyViolation";
509
- })(ResponseErrorType || (ResponseErrorType = {}));
510
- class SwaggerException extends Error {
511
- constructor(message, status, response, headers, result) {
512
- super();
513
- this.isSwaggerException = true;
514
- this.message = message;
515
- this.status = status;
516
- this.response = response;
517
- this.headers = headers;
518
- this.result = result;
519
- }
520
- static isSwaggerException(obj) {
521
- return obj.isSwaggerException === true;
522
- }
523
- }
524
- function throwException(message, status, response, headers, result) {
525
- if (result !== null && result !== undefined)
526
- return throwError(result);
527
- else
528
- return throwError(new SwaggerException(message, status, response, headers, null));
529
- }
530
- function blobToText(blob) {
531
- return new Observable((observer) => {
532
- if (!blob) {
533
- observer.next("");
534
- observer.complete();
535
- }
536
- else {
537
- let reader = new FileReader();
538
- reader.onload = event => {
539
- observer.next(event.target.result);
540
- observer.complete();
541
- };
542
- reader.readAsText(blob);
543
- }
544
- });
9
+ //----------------------
10
+ // <auto-generated>
11
+ // Generated using the NSwag toolchain v14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
12
+ // </auto-generated>
13
+ //----------------------
14
+ /* tslint:disable */
15
+ /* eslint-disable */
16
+ // ReSharper disable InconsistentNaming
17
+ const DANGL_IDENTITY_CLIENT_API_BASE_URL = new InjectionToken('DANGL_IDENTITY_CLIENT_API_BASE_URL');
18
+ class DanglIdentityClient {
19
+ constructor(http, baseUrl) {
20
+ this.jsonParseReviver = undefined;
21
+ this.http = http;
22
+ this.baseUrl = baseUrl ?? "";
23
+ }
24
+ loginWithCookie(model, redirectUrl) {
25
+ let url_ = this.baseUrl + "/identity/login?";
26
+ if (redirectUrl !== undefined && redirectUrl !== null)
27
+ url_ += "redirectUrl=" + encodeURIComponent("" + redirectUrl) + "&";
28
+ url_ = url_.replace(/[?&]$/, "");
29
+ const content_ = JSON.stringify(model);
30
+ let options_ = {
31
+ body: content_,
32
+ observe: "response",
33
+ responseType: "blob",
34
+ headers: new HttpHeaders({
35
+ "Content-Type": "application/json",
36
+ })
37
+ };
38
+ return this.http.request("post", url_, options_).pipe(mergeMap((response_) => {
39
+ return this.processLoginWithCookie(response_);
40
+ })).pipe(catchError((response_) => {
41
+ if (response_ instanceof HttpResponseBase) {
42
+ try {
43
+ return this.processLoginWithCookie(response_);
44
+ }
45
+ catch (e) {
46
+ return throwError(e);
47
+ }
48
+ }
49
+ else
50
+ return throwError(response_);
51
+ }));
52
+ }
53
+ processLoginWithCookie(response) {
54
+ const status = response.status;
55
+ const responseBlob = response instanceof HttpResponse ? response.body :
56
+ response.error instanceof Blob ? response.error : undefined;
57
+ let _headers = {};
58
+ if (response.headers) {
59
+ for (let key of response.headers.keys()) {
60
+ _headers[key] = response.headers.get(key);
61
+ }
62
+ }
63
+ if (status === 204) {
64
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
65
+ return of(null);
66
+ }));
67
+ }
68
+ else if (status === 401) {
69
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
70
+ return throwException("A server side error occurred.", status, _responseText, _headers);
71
+ }));
72
+ }
73
+ else if (status !== 200 && status !== 204) {
74
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
75
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
76
+ }));
77
+ }
78
+ return of(null);
79
+ }
80
+ signOutWithSignInManager() {
81
+ let url_ = this.baseUrl + "/identity/login";
82
+ url_ = url_.replace(/[?&]$/, "");
83
+ let options_ = {
84
+ observe: "response",
85
+ responseType: "blob",
86
+ headers: new HttpHeaders({})
87
+ };
88
+ return this.http.request("delete", url_, options_).pipe(mergeMap((response_) => {
89
+ return this.processSignOutWithSignInManager(response_);
90
+ })).pipe(catchError((response_) => {
91
+ if (response_ instanceof HttpResponseBase) {
92
+ try {
93
+ return this.processSignOutWithSignInManager(response_);
94
+ }
95
+ catch (e) {
96
+ return throwError(e);
97
+ }
98
+ }
99
+ else
100
+ return throwError(response_);
101
+ }));
102
+ }
103
+ processSignOutWithSignInManager(response) {
104
+ const status = response.status;
105
+ const responseBlob = response instanceof HttpResponse ? response.body :
106
+ response.error instanceof Blob ? response.error : undefined;
107
+ let _headers = {};
108
+ if (response.headers) {
109
+ for (let key of response.headers.keys()) {
110
+ _headers[key] = response.headers.get(key);
111
+ }
112
+ }
113
+ if (status === 204) {
114
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
115
+ return of(null);
116
+ }));
117
+ }
118
+ else if (status !== 200 && status !== 204) {
119
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
120
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
121
+ }));
122
+ }
123
+ return of(null);
124
+ }
125
+ loginAndReturnToken(model) {
126
+ let url_ = this.baseUrl + "/identity/token-login";
127
+ url_ = url_.replace(/[?&]$/, "");
128
+ const content_ = JSON.stringify(model);
129
+ let options_ = {
130
+ body: content_,
131
+ observe: "response",
132
+ responseType: "blob",
133
+ headers: new HttpHeaders({
134
+ "Content-Type": "application/json",
135
+ "Accept": "application/json"
136
+ })
137
+ };
138
+ return this.http.request("post", url_, options_).pipe(mergeMap((response_) => {
139
+ return this.processLoginAndReturnToken(response_);
140
+ })).pipe(catchError((response_) => {
141
+ if (response_ instanceof HttpResponseBase) {
142
+ try {
143
+ return this.processLoginAndReturnToken(response_);
144
+ }
145
+ catch (e) {
146
+ return throwError(e);
147
+ }
148
+ }
149
+ else
150
+ return throwError(response_);
151
+ }));
152
+ }
153
+ processLoginAndReturnToken(response) {
154
+ const status = response.status;
155
+ const responseBlob = response instanceof HttpResponse ? response.body :
156
+ response.error instanceof Blob ? response.error : undefined;
157
+ let _headers = {};
158
+ if (response.headers) {
159
+ for (let key of response.headers.keys()) {
160
+ _headers[key] = response.headers.get(key);
161
+ }
162
+ }
163
+ if (status === 200) {
164
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
165
+ let result200 = null;
166
+ result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
167
+ return of(result200);
168
+ }));
169
+ }
170
+ else if (status === 400) {
171
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
172
+ let result400 = null;
173
+ result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
174
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
175
+ }));
176
+ }
177
+ else if (status === 401) {
178
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
179
+ return throwException("A server side error occurred.", status, _responseText, _headers);
180
+ }));
181
+ }
182
+ else if (status !== 200 && status !== 204) {
183
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
184
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
185
+ }));
186
+ }
187
+ return of(null);
188
+ }
189
+ refreshToken(model) {
190
+ let url_ = this.baseUrl + "/identity/token-refresh";
191
+ url_ = url_.replace(/[?&]$/, "");
192
+ const content_ = JSON.stringify(model);
193
+ let options_ = {
194
+ body: content_,
195
+ observe: "response",
196
+ responseType: "blob",
197
+ headers: new HttpHeaders({
198
+ "Content-Type": "application/json",
199
+ "Accept": "application/json"
200
+ })
201
+ };
202
+ return this.http.request("post", url_, options_).pipe(mergeMap((response_) => {
203
+ return this.processRefreshToken(response_);
204
+ })).pipe(catchError((response_) => {
205
+ if (response_ instanceof HttpResponseBase) {
206
+ try {
207
+ return this.processRefreshToken(response_);
208
+ }
209
+ catch (e) {
210
+ return throwError(e);
211
+ }
212
+ }
213
+ else
214
+ return throwError(response_);
215
+ }));
216
+ }
217
+ processRefreshToken(response) {
218
+ const status = response.status;
219
+ const responseBlob = response instanceof HttpResponse ? response.body :
220
+ response.error instanceof Blob ? response.error : undefined;
221
+ let _headers = {};
222
+ if (response.headers) {
223
+ for (let key of response.headers.keys()) {
224
+ _headers[key] = response.headers.get(key);
225
+ }
226
+ }
227
+ if (status === 200) {
228
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
229
+ let result200 = null;
230
+ result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
231
+ return of(result200);
232
+ }));
233
+ }
234
+ else if (status === 400) {
235
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
236
+ let result400 = null;
237
+ result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
238
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
239
+ }));
240
+ }
241
+ else if (status === 401) {
242
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
243
+ return throwException("A server side error occurred.", status, _responseText, _headers);
244
+ }));
245
+ }
246
+ else if (status !== 200 && status !== 204) {
247
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
248
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
249
+ }));
250
+ }
251
+ return of(null);
252
+ }
253
+ register(registerModel) {
254
+ let url_ = this.baseUrl + "/identity/register";
255
+ url_ = url_.replace(/[?&]$/, "");
256
+ const content_ = JSON.stringify(registerModel);
257
+ let options_ = {
258
+ body: content_,
259
+ observe: "response",
260
+ responseType: "blob",
261
+ headers: new HttpHeaders({
262
+ "Content-Type": "application/json",
263
+ })
264
+ };
265
+ return this.http.request("post", url_, options_).pipe(mergeMap((response_) => {
266
+ return this.processRegister(response_);
267
+ })).pipe(catchError((response_) => {
268
+ if (response_ instanceof HttpResponseBase) {
269
+ try {
270
+ return this.processRegister(response_);
271
+ }
272
+ catch (e) {
273
+ return throwError(e);
274
+ }
275
+ }
276
+ else
277
+ return throwError(response_);
278
+ }));
279
+ }
280
+ processRegister(response) {
281
+ const status = response.status;
282
+ const responseBlob = response instanceof HttpResponse ? response.body :
283
+ response.error instanceof Blob ? response.error : undefined;
284
+ let _headers = {};
285
+ if (response.headers) {
286
+ for (let key of response.headers.keys()) {
287
+ _headers[key] = response.headers.get(key);
288
+ }
289
+ }
290
+ if (status === 204) {
291
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
292
+ return of(null);
293
+ }));
294
+ }
295
+ else if (status === 400) {
296
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
297
+ let result400 = null;
298
+ result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
299
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
300
+ }));
301
+ }
302
+ else if (status !== 200 && status !== 204) {
303
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
304
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
305
+ }));
306
+ }
307
+ return of(null);
308
+ }
309
+ requestPasswordReset(forgotPasswordModel) {
310
+ let url_ = this.baseUrl + "/identity/password-forgotten";
311
+ url_ = url_.replace(/[?&]$/, "");
312
+ const content_ = JSON.stringify(forgotPasswordModel);
313
+ let options_ = {
314
+ body: content_,
315
+ observe: "response",
316
+ responseType: "blob",
317
+ headers: new HttpHeaders({
318
+ "Content-Type": "application/json",
319
+ })
320
+ };
321
+ return this.http.request("post", url_, options_).pipe(mergeMap((response_) => {
322
+ return this.processRequestPasswordReset(response_);
323
+ })).pipe(catchError((response_) => {
324
+ if (response_ instanceof HttpResponseBase) {
325
+ try {
326
+ return this.processRequestPasswordReset(response_);
327
+ }
328
+ catch (e) {
329
+ return throwError(e);
330
+ }
331
+ }
332
+ else
333
+ return throwError(response_);
334
+ }));
335
+ }
336
+ processRequestPasswordReset(response) {
337
+ const status = response.status;
338
+ const responseBlob = response instanceof HttpResponse ? response.body :
339
+ response.error instanceof Blob ? response.error : undefined;
340
+ let _headers = {};
341
+ if (response.headers) {
342
+ for (let key of response.headers.keys()) {
343
+ _headers[key] = response.headers.get(key);
344
+ }
345
+ }
346
+ if (status === 204) {
347
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
348
+ return of(null);
349
+ }));
350
+ }
351
+ else if (status === 400) {
352
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
353
+ let result400 = null;
354
+ result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
355
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
356
+ }));
357
+ }
358
+ else if (status !== 200 && status !== 204) {
359
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
360
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
361
+ }));
362
+ }
363
+ return of(null);
364
+ }
365
+ getUserInfo() {
366
+ let url_ = this.baseUrl + "/identity/user-info";
367
+ url_ = url_.replace(/[?&]$/, "");
368
+ let options_ = {
369
+ observe: "response",
370
+ responseType: "blob",
371
+ headers: new HttpHeaders({
372
+ "Accept": "application/json"
373
+ })
374
+ };
375
+ return this.http.request("get", url_, options_).pipe(mergeMap((response_) => {
376
+ return this.processGetUserInfo(response_);
377
+ })).pipe(catchError((response_) => {
378
+ if (response_ instanceof HttpResponseBase) {
379
+ try {
380
+ return this.processGetUserInfo(response_);
381
+ }
382
+ catch (e) {
383
+ return throwError(e);
384
+ }
385
+ }
386
+ else
387
+ return throwError(response_);
388
+ }));
389
+ }
390
+ processGetUserInfo(response) {
391
+ const status = response.status;
392
+ const responseBlob = response instanceof HttpResponse ? response.body :
393
+ response.error instanceof Blob ? response.error : undefined;
394
+ let _headers = {};
395
+ if (response.headers) {
396
+ for (let key of response.headers.keys()) {
397
+ _headers[key] = response.headers.get(key);
398
+ }
399
+ }
400
+ if (status === 200) {
401
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
402
+ let result200 = null;
403
+ result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
404
+ return of(result200);
405
+ }));
406
+ }
407
+ else if (status === 400) {
408
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
409
+ let result400 = null;
410
+ result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
411
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
412
+ }));
413
+ }
414
+ else if (status !== 200 && status !== 204) {
415
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
416
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
417
+ }));
418
+ }
419
+ return of(null);
420
+ }
421
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: DanglIdentityClient, deps: [{ token: HttpClient }, { token: DANGL_IDENTITY_CLIENT_API_BASE_URL, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
422
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: DanglIdentityClient, providedIn: 'root' }); }
423
+ }
424
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: DanglIdentityClient, decorators: [{
425
+ type: Injectable,
426
+ args: [{
427
+ providedIn: 'root'
428
+ }]
429
+ }], ctorParameters: () => [{ type: i1.HttpClient, decorators: [{
430
+ type: Inject,
431
+ args: [HttpClient]
432
+ }] }, { type: undefined, decorators: [{
433
+ type: Optional
434
+ }, {
435
+ type: Inject,
436
+ args: [DANGL_IDENTITY_CLIENT_API_BASE_URL]
437
+ }] }] });
438
+ var HttpStatusCode;
439
+ (function (HttpStatusCode) {
440
+ HttpStatusCode["Continue"] = "Continue";
441
+ HttpStatusCode["SwitchingProtocols"] = "SwitchingProtocols";
442
+ HttpStatusCode["Processing"] = "Processing";
443
+ HttpStatusCode["EarlyHints"] = "EarlyHints";
444
+ HttpStatusCode["OK"] = "OK";
445
+ HttpStatusCode["Created"] = "Created";
446
+ HttpStatusCode["Accepted"] = "Accepted";
447
+ HttpStatusCode["NonAuthoritativeInformation"] = "NonAuthoritativeInformation";
448
+ HttpStatusCode["NoContent"] = "NoContent";
449
+ HttpStatusCode["ResetContent"] = "ResetContent";
450
+ HttpStatusCode["PartialContent"] = "PartialContent";
451
+ HttpStatusCode["MultiStatus"] = "MultiStatus";
452
+ HttpStatusCode["AlreadyReported"] = "AlreadyReported";
453
+ HttpStatusCode["IMUsed"] = "IMUsed";
454
+ HttpStatusCode["MultipleChoices"] = "MultipleChoices";
455
+ HttpStatusCode["Ambiguous"] = "MultipleChoices";
456
+ HttpStatusCode["MovedPermanently"] = "MovedPermanently";
457
+ HttpStatusCode["Moved"] = "MovedPermanently";
458
+ HttpStatusCode["Found"] = "Found";
459
+ HttpStatusCode["Redirect"] = "Found";
460
+ HttpStatusCode["SeeOther"] = "SeeOther";
461
+ HttpStatusCode["RedirectMethod"] = "SeeOther";
462
+ HttpStatusCode["NotModified"] = "NotModified";
463
+ HttpStatusCode["UseProxy"] = "UseProxy";
464
+ HttpStatusCode["Unused"] = "Unused";
465
+ HttpStatusCode["TemporaryRedirect"] = "TemporaryRedirect";
466
+ HttpStatusCode["RedirectKeepVerb"] = "TemporaryRedirect";
467
+ HttpStatusCode["PermanentRedirect"] = "PermanentRedirect";
468
+ HttpStatusCode["BadRequest"] = "BadRequest";
469
+ HttpStatusCode["Unauthorized"] = "Unauthorized";
470
+ HttpStatusCode["PaymentRequired"] = "PaymentRequired";
471
+ HttpStatusCode["Forbidden"] = "Forbidden";
472
+ HttpStatusCode["NotFound"] = "NotFound";
473
+ HttpStatusCode["MethodNotAllowed"] = "MethodNotAllowed";
474
+ HttpStatusCode["NotAcceptable"] = "NotAcceptable";
475
+ HttpStatusCode["ProxyAuthenticationRequired"] = "ProxyAuthenticationRequired";
476
+ HttpStatusCode["RequestTimeout"] = "RequestTimeout";
477
+ HttpStatusCode["Conflict"] = "Conflict";
478
+ HttpStatusCode["Gone"] = "Gone";
479
+ HttpStatusCode["LengthRequired"] = "LengthRequired";
480
+ HttpStatusCode["PreconditionFailed"] = "PreconditionFailed";
481
+ HttpStatusCode["RequestEntityTooLarge"] = "RequestEntityTooLarge";
482
+ HttpStatusCode["RequestUriTooLong"] = "RequestUriTooLong";
483
+ HttpStatusCode["UnsupportedMediaType"] = "UnsupportedMediaType";
484
+ HttpStatusCode["RequestedRangeNotSatisfiable"] = "RequestedRangeNotSatisfiable";
485
+ HttpStatusCode["ExpectationFailed"] = "ExpectationFailed";
486
+ HttpStatusCode["MisdirectedRequest"] = "MisdirectedRequest";
487
+ HttpStatusCode["UnprocessableEntity"] = "UnprocessableEntity";
488
+ HttpStatusCode["UnprocessableContent"] = "UnprocessableEntity";
489
+ HttpStatusCode["Locked"] = "Locked";
490
+ HttpStatusCode["FailedDependency"] = "FailedDependency";
491
+ HttpStatusCode["UpgradeRequired"] = "UpgradeRequired";
492
+ HttpStatusCode["PreconditionRequired"] = "PreconditionRequired";
493
+ HttpStatusCode["TooManyRequests"] = "TooManyRequests";
494
+ HttpStatusCode["RequestHeaderFieldsTooLarge"] = "RequestHeaderFieldsTooLarge";
495
+ HttpStatusCode["UnavailableForLegalReasons"] = "UnavailableForLegalReasons";
496
+ HttpStatusCode["InternalServerError"] = "InternalServerError";
497
+ HttpStatusCode["NotImplemented"] = "NotImplemented";
498
+ HttpStatusCode["BadGateway"] = "BadGateway";
499
+ HttpStatusCode["ServiceUnavailable"] = "ServiceUnavailable";
500
+ HttpStatusCode["GatewayTimeout"] = "GatewayTimeout";
501
+ HttpStatusCode["HttpVersionNotSupported"] = "HttpVersionNotSupported";
502
+ HttpStatusCode["VariantAlsoNegotiates"] = "VariantAlsoNegotiates";
503
+ HttpStatusCode["InsufficientStorage"] = "InsufficientStorage";
504
+ HttpStatusCode["LoopDetected"] = "LoopDetected";
505
+ HttpStatusCode["NotExtended"] = "NotExtended";
506
+ HttpStatusCode["NetworkAuthenticationRequired"] = "NetworkAuthenticationRequired";
507
+ })(HttpStatusCode || (HttpStatusCode = {}));
508
+ /** Various reasons for a protocol endpoint error */
509
+ var ResponseErrorType;
510
+ (function (ResponseErrorType) {
511
+ ResponseErrorType["None"] = "None";
512
+ ResponseErrorType["Protocol"] = "Protocol";
513
+ ResponseErrorType["Http"] = "Http";
514
+ ResponseErrorType["Exception"] = "Exception";
515
+ ResponseErrorType["PolicyViolation"] = "PolicyViolation";
516
+ })(ResponseErrorType || (ResponseErrorType = {}));
517
+ class SwaggerException extends Error {
518
+ constructor(message, status, response, headers, result) {
519
+ super();
520
+ this.isSwaggerException = true;
521
+ this.message = message;
522
+ this.status = status;
523
+ this.response = response;
524
+ this.headers = headers;
525
+ this.result = result;
526
+ }
527
+ static isSwaggerException(obj) {
528
+ return obj.isSwaggerException === true;
529
+ }
530
+ }
531
+ function throwException(message, status, response, headers, result) {
532
+ if (result !== null && result !== undefined)
533
+ return throwError(result);
534
+ else
535
+ return throwError(new SwaggerException(message, status, response, headers, null));
536
+ }
537
+ function blobToText(blob) {
538
+ return new Observable((observer) => {
539
+ if (!blob) {
540
+ observer.next("");
541
+ observer.complete();
542
+ }
543
+ else {
544
+ let reader = new FileReader();
545
+ reader.onload = event => {
546
+ observer.next(event.target.result);
547
+ observer.complete();
548
+ };
549
+ reader.readAsText(blob);
550
+ }
551
+ });
545
552
  }
546
553
 
547
- class JwtTokenService {
548
- constructor(danglIdentityClient) {
549
- this.danglIdentityClient = danglIdentityClient;
550
- this.storage_identifier = 'dangl_identity_integration_jwt_token';
551
- this.isRefreshing = false;
552
- this.refreshTokenSource = new Subject();
553
- this.tokenStoredSource = new ReplaySubject(1);
554
- this.tokenStored = this.tokenStoredSource.asObservable();
555
- this.tokenRefreshStartedSource = new Subject();
556
- this.tokenRefreshStarted = this.tokenRefreshStartedSource.asObservable();
557
- this.tokenRefreshFinishedSource = new Subject();
558
- this.tokenRefreshFinished = this.tokenRefreshFinishedSource.asObservable();
559
- }
560
- ngOnDestroy() {
561
- this.tokenRefreshStartedSource.complete();
562
- this.tokenRefreshFinishedSource.complete();
563
- this.tokenStoredSource.complete();
564
- this.refreshTokenSource.complete();
565
- }
566
- deleteToken() {
567
- localStorage.removeItem(this.storage_identifier);
568
- this.tokenStoredSource.next(null);
569
- }
570
- storeCustomToken(tokenToStore) {
571
- localStorage.setItem(this.storage_identifier, JSON.stringify(tokenToStore));
572
- this.tokenStoredSource.next(tokenToStore);
573
- }
574
- storeToken(token) {
575
- const tokenToStore = this.transformTokenResponse(token);
576
- localStorage.setItem(this.storage_identifier, JSON.stringify(tokenToStore));
577
- this.tokenStoredSource.next(tokenToStore);
578
- }
579
- getTokenFromStorage() {
580
- const storedString = localStorage.getItem(this.storage_identifier);
581
- if (storedString) {
582
- const storedToken = JSON.parse(storedString);
583
- return storedToken;
584
- }
585
- return null;
586
- }
587
- refreshToken() {
588
- if (this.isRefreshing) {
589
- return this.refreshTokenSource.pipe(first());
590
- }
591
- this.isRefreshing = true;
592
- this.tokenRefreshStartedSource.next();
593
- const refreshToken = this.getTokenFromStorage().refreshToken;
594
- if (!refreshToken) {
595
- this.isRefreshing = false;
596
- return of(null);
597
- }
598
- this.danglIdentityClient
599
- .refreshToken({
600
- refreshToken: refreshToken,
601
- })
602
- .pipe(tap((r) => this.storeToken(r)), map((r) => this.transformTokenResponse(r)))
603
- .subscribe((refreshTokenResponse) => {
604
- this.isRefreshing = false;
605
- this.tokenRefreshFinishedSource.next(true);
606
- this.refreshTokenSource.next(refreshTokenResponse);
607
- }, (error) => {
608
- this.isRefreshing = false;
609
- this.tokenRefreshFinishedSource.next(false);
610
- this.refreshTokenSource.next(null);
611
- console.error('Internal error while refreshing Dangl.Identity token', error);
612
- });
613
- return this.refreshTokenSource.pipe(first());
614
- }
615
- getToken() {
616
- const token = this.getTokenFromStorage();
617
- if (!token) {
618
- return of(null);
619
- }
620
- const isValidToken = token.expiresAt > new Date().getTime() / 1000;
621
- if (isValidToken) {
622
- return of(token);
623
- }
624
- return this.refreshToken();
625
- }
626
- transformTokenResponse(token) {
627
- return {
628
- accessToken: token.accessToken,
629
- refreshToken: token.refreshToken,
630
- expiresAt: new Date().getTime() / 1000 + token.expiresIn,
631
- };
632
- }
633
- }
634
- JwtTokenServicefac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: JwtTokenService, deps: [{ token: DanglIdentityClient }], target: i0.ɵɵFactoryTarget.Injectable });
635
- JwtTokenService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: JwtTokenService, providedIn: 'root' });
636
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: JwtTokenService, decorators: [{
637
- type: Injectable,
638
- args: [{
639
- providedIn: 'root',
640
- }]
641
- }], ctorParameters: function () { return [{ type: DanglIdentityClient }]; } });
554
+ class JwtTokenService {
555
+ constructor(danglIdentityClient) {
556
+ this.danglIdentityClient = danglIdentityClient;
557
+ this.storage_identifier = 'dangl_identity_integration_jwt_token';
558
+ this.isRefreshing = false;
559
+ this.refreshTokenSource = new Subject();
560
+ this.tokenStoredSource = new ReplaySubject(1);
561
+ this.tokenStored = this.tokenStoredSource.asObservable();
562
+ this.tokenRefreshStartedSource = new Subject();
563
+ this.tokenRefreshStarted = this.tokenRefreshStartedSource.asObservable();
564
+ this.tokenRefreshFinishedSource = new Subject();
565
+ this.tokenRefreshFinished = this.tokenRefreshFinishedSource.asObservable();
566
+ }
567
+ ngOnDestroy() {
568
+ this.tokenRefreshStartedSource.complete();
569
+ this.tokenRefreshFinishedSource.complete();
570
+ this.tokenStoredSource.complete();
571
+ this.refreshTokenSource.complete();
572
+ }
573
+ deleteToken() {
574
+ localStorage.removeItem(this.storage_identifier);
575
+ this.tokenStoredSource.next(null);
576
+ }
577
+ storeCustomToken(tokenToStore) {
578
+ localStorage.setItem(this.storage_identifier, JSON.stringify(tokenToStore));
579
+ this.tokenStoredSource.next(tokenToStore);
580
+ }
581
+ storeToken(token) {
582
+ const tokenToStore = this.transformTokenResponse(token);
583
+ localStorage.setItem(this.storage_identifier, JSON.stringify(tokenToStore));
584
+ this.tokenStoredSource.next(tokenToStore);
585
+ }
586
+ getTokenFromStorage() {
587
+ const storedString = localStorage.getItem(this.storage_identifier);
588
+ if (storedString) {
589
+ const storedToken = JSON.parse(storedString);
590
+ return storedToken;
591
+ }
592
+ return null;
593
+ }
594
+ refreshToken() {
595
+ if (this.isRefreshing) {
596
+ return this.refreshTokenSource.pipe(first());
597
+ }
598
+ this.isRefreshing = true;
599
+ this.tokenRefreshStartedSource.next();
600
+ const refreshToken = this.getTokenFromStorage().refreshToken;
601
+ if (!refreshToken) {
602
+ this.isRefreshing = false;
603
+ return of(null);
604
+ }
605
+ this.danglIdentityClient
606
+ .refreshToken({
607
+ refreshToken: refreshToken,
608
+ })
609
+ .pipe(tap((r) => this.storeToken(r)), map((r) => this.transformTokenResponse(r)))
610
+ .subscribe((refreshTokenResponse) => {
611
+ this.isRefreshing = false;
612
+ this.tokenRefreshFinishedSource.next(true);
613
+ this.refreshTokenSource.next(refreshTokenResponse);
614
+ }, (error) => {
615
+ this.isRefreshing = false;
616
+ this.tokenRefreshFinishedSource.next(false);
617
+ this.refreshTokenSource.next(null);
618
+ console.error('Internal error while refreshing Dangl.Identity token', error);
619
+ });
620
+ return this.refreshTokenSource.pipe(first());
621
+ }
622
+ getToken() {
623
+ const token = this.getTokenFromStorage();
624
+ if (!token) {
625
+ return of(null);
626
+ }
627
+ const isValidToken = token.expiresAt > new Date().getTime() / 1000;
628
+ if (isValidToken) {
629
+ return of(token);
630
+ }
631
+ return this.refreshToken();
632
+ }
633
+ transformTokenResponse(token) {
634
+ return {
635
+ accessToken: token.accessToken,
636
+ refreshToken: token.refreshToken,
637
+ expiresAt: new Date().getTime() / 1000 + token.expiresIn,
638
+ };
639
+ }
640
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: JwtTokenService, deps: [{ token: DanglIdentityClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
641
+ static { thisprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: JwtTokenService, providedIn: 'root' }); }
642
+ }
643
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: JwtTokenService, decorators: [{
644
+ type: Injectable,
645
+ args: [{
646
+ providedIn: 'root',
647
+ }]
648
+ }], ctorParameters: () => [{ type: DanglIdentityClient }] });
642
649
 
643
- const DANGL_IDENTITY_REQUEST_VALIDATOR = new InjectionToken('Validator to decide whether to include JWT tokens in requests');
644
- class JwtInterceptorService {
645
- constructor(jwtTokenService, requestValidator) {
646
- this.jwtTokenService = jwtTokenService;
647
- this.requestValidator = requestValidator;
648
- }
649
- intercept(request, next) {
650
- if (request.url.startsWith('/identity')) {
651
- // Requests to the authentication endpoint should not be intercepted
652
- return next.handle(request.clone());
653
- }
654
- if (this.requestValidator &&
655
- !this.requestValidator.validateRequest(request)) {
656
- // In case a request validator is provided but doesn't return true for the
657
- // current request, we're not appending a token
658
- return next.handle(request);
659
- }
660
- return this.jwtTokenService
661
- .getToken()
662
- .pipe(mergeMap((f) => next.handle(this.getHttpRequestWithToken(request, f && f.accessToken))));
663
- }
664
- getHttpRequestWithToken(request, token) {
665
- if (token) {
666
- return request.clone({
667
- setHeaders: {
668
- Authorization: `Bearer ${token}`,
669
- },
670
- });
671
- }
672
- return request.clone();
673
- }
674
- }
675
- JwtInterceptorServicefac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: JwtInterceptorService, deps: [{ token: JwtTokenService }, { token: DANGL_IDENTITY_REQUEST_VALIDATOR, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
676
- JwtInterceptorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: JwtInterceptorService });
677
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: JwtInterceptorService, decorators: [{
678
- type: Injectable
679
- }], ctorParameters: function () { return [{ type: JwtTokenService }, { type: undefined, decorators: [{
680
- type: Optional
681
- }, {
682
- type: Inject,
683
- args: [DANGL_IDENTITY_REQUEST_VALIDATOR]
684
- }] }]; } });
650
+ const DANGL_IDENTITY_REQUEST_VALIDATOR = new InjectionToken('Validator to decide whether to include JWT tokens in requests');
651
+ class JwtInterceptorService {
652
+ constructor(jwtTokenService, requestValidator) {
653
+ this.jwtTokenService = jwtTokenService;
654
+ this.requestValidator = requestValidator;
655
+ }
656
+ intercept(request, next) {
657
+ if (request.url.startsWith('/identity')) {
658
+ // Requests to the authentication endpoint should not be intercepted
659
+ return next.handle(request.clone());
660
+ }
661
+ if (this.requestValidator &&
662
+ !this.requestValidator.validateRequest(request)) {
663
+ // In case a request validator is provided but doesn't return true for the
664
+ // current request, we're not appending a token
665
+ return next.handle(request);
666
+ }
667
+ return this.jwtTokenService
668
+ .getToken()
669
+ .pipe(mergeMap((f) => next.handle(this.getHttpRequestWithToken(request, f && f.accessToken))));
670
+ }
671
+ getHttpRequestWithToken(request, token) {
672
+ if (token) {
673
+ return request.clone({
674
+ setHeaders: {
675
+ Authorization: `Bearer ${token}`,
676
+ },
677
+ });
678
+ }
679
+ return request.clone();
680
+ }
681
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: JwtInterceptorService, deps: [{ token: JwtTokenService }, { token: DANGL_IDENTITY_REQUEST_VALIDATOR, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
682
+ static { thisprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: JwtInterceptorService }); }
683
+ }
684
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: JwtInterceptorService, decorators: [{
685
+ type: Injectable
686
+ }], ctorParameters: () => [{ type: JwtTokenService }, { type: undefined, decorators: [{
687
+ type: Optional
688
+ }, {
689
+ type: Inject,
690
+ args: [DANGL_IDENTITY_REQUEST_VALIDATOR]
691
+ }] }] });
685
692
 
686
- class DanglIdentityModule {
687
- }
688
- DanglIdentityModulefac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: DanglIdentityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
689
- DanglIdentityModulemod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.4", ngImport: i0, type: DanglIdentityModule, imports: [HttpClientModule] });
690
- DanglIdentityModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: DanglIdentityModule, providers: [
691
- {
692
- provide: HTTP_INTERCEPTORS,
693
- useClass: JwtInterceptorService,
694
- multi: true,
695
- },
696
- ], imports: [HttpClientModule] });
697
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: DanglIdentityModule, decorators: [{
698
- type: NgModule,
699
- args: [{
700
- imports: [HttpClientModule],
701
- providers: [
702
- {
703
- provide: HTTP_INTERCEPTORS,
704
- useClass: JwtInterceptorService,
705
- multi: true,
706
- },
707
- ],
708
- }]
693
+ class DanglIdentityModule {
694
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: DanglIdentityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
695
+ static { thismod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.1.3", ngImport: i0, type: DanglIdentityModule }); }
696
+ static { thisinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: DanglIdentityModule, providers: [
697
+ provideHttpClient(withInterceptorsFromDi()),
698
+ {
699
+ provide: HTTP_INTERCEPTORS,
700
+ useClass: JwtInterceptorService,
701
+ multi: true,
702
+ },
703
+ ] }); }
704
+ }
705
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: DanglIdentityModule, decorators: [{
706
+ type: NgModule,
707
+ args: [{
708
+ providers: [
709
+ provideHttpClient(withInterceptorsFromDi()),
710
+ {
711
+ provide: HTTP_INTERCEPTORS,
712
+ useClass: JwtInterceptorService,
713
+ multi: true,
714
+ },
715
+ ],
716
+ }]
709
717
  }] });
710
718
 
711
- class AuthenticationService {
712
- constructor(danglIdentityClient, jwtTokenService) {
713
- this.danglIdentityClient = danglIdentityClient;
714
- this.jwtTokenService = jwtTokenService;
715
- }
716
- loginWithToken(identifier, password) {
717
- return this.danglIdentityClient
718
- .loginAndReturnToken({
719
- identifier: identifier,
720
- password: password,
721
- })
722
- .pipe(map((r) => this.storeJwtTokenIfValid(r)), catchError((e) => of(false)));
723
- }
724
- storeJwtTokenIfValid(token) {
725
- if (!token.accessToken || !token.refreshToken || !token.expiresIn) {
726
- return false;
727
- }
728
- this.jwtTokenService.storeToken(token);
729
- return true;
730
- }
731
- logout() {
732
- this.jwtTokenService.deleteToken();
733
- }
734
- }
735
- AuthenticationServicefac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: AuthenticationService, deps: [{ token: DanglIdentityClient }, { token: JwtTokenService }], target: i0.ɵɵFactoryTarget.Injectable });
736
- AuthenticationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: AuthenticationService, providedIn: 'root' });
737
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: AuthenticationService, decorators: [{
738
- type: Injectable,
739
- args: [{
740
- providedIn: 'root',
741
- }]
742
- }], ctorParameters: function () { return [{ type: DanglIdentityClient }, { type: JwtTokenService }]; } });
719
+ class AuthenticationService {
720
+ constructor(danglIdentityClient, jwtTokenService) {
721
+ this.danglIdentityClient = danglIdentityClient;
722
+ this.jwtTokenService = jwtTokenService;
723
+ }
724
+ loginWithToken(identifier, password) {
725
+ return this.danglIdentityClient
726
+ .loginAndReturnToken({
727
+ identifier: identifier,
728
+ password: password,
729
+ })
730
+ .pipe(map((r) => this.storeJwtTokenIfValid(r)), catchError((e) => of(false)));
731
+ }
732
+ storeJwtTokenIfValid(token) {
733
+ if (!token.accessToken || !token.refreshToken || !token.expiresIn) {
734
+ return false;
735
+ }
736
+ this.jwtTokenService.storeToken(token);
737
+ return true;
738
+ }
739
+ logout() {
740
+ this.jwtTokenService.deleteToken();
741
+ }
742
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: AuthenticationService, deps: [{ token: DanglIdentityClient }, { token: JwtTokenService }], target: i0.ɵɵFactoryTarget.Injectable }); }
743
+ static { thisprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: AuthenticationService, providedIn: 'root' }); }
744
+ }
745
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: AuthenticationService, decorators: [{
746
+ type: Injectable,
747
+ args: [{
748
+ providedIn: 'root',
749
+ }]
750
+ }], ctorParameters: () => [{ type: DanglIdentityClient }, { type: JwtTokenService }] });
743
751
 
744
- class AuthenticationMessenger {
745
- constructor(jwtTokenService, danglIdentityClient) {
746
- this.jwtTokenService = jwtTokenService;
747
- this.danglIdentityClient = danglIdentityClient;
748
- this.jwtHelperService = new JwtHelperService();
749
- this.$destroyed = new Subject();
750
- this.isAuthenticated = new ReplaySubject(1);
751
- this.username = new ReplaySubject(1);
752
- this.email = new ReplaySubject(1);
753
- this.identiconId = new ReplaySubject(1);
754
- this.userInfo = new ReplaySubject(1);
755
- this.tokenRefreshStarted = new Subject();
756
- this.tokenRefreshFinished = new Subject();
757
- jwtTokenService.tokenRefreshStarted
758
- .pipe(takeUntil(this.$destroyed))
759
- .subscribe(() => this.tokenRefreshStarted.next());
760
- jwtTokenService.tokenRefreshFinished
761
- .pipe(takeUntil(this.$destroyed))
762
- .subscribe((successfulRefresh) => this.tokenRefreshFinished.next(successfulRefresh));
763
- jwtTokenService.tokenStored
764
- .pipe(takeUntil(this.$destroyed))
765
- .subscribe((jwtToken) => this.refreshAuthenticationStatus(jwtToken));
766
- jwtTokenService
767
- .getToken()
768
- .subscribe((token) => this.refreshAuthenticationStatus(token));
769
- }
770
- ngOnDestroy() {
771
- this.isAuthenticated.complete();
772
- this.username.complete();
773
- this.email.complete();
774
- this.identiconId.complete();
775
- this.userInfo.complete();
776
- this.tokenRefreshStarted.complete();
777
- this.tokenRefreshFinished.complete();
778
- this.$destroyed.next();
779
- this.$destroyed.complete();
780
- }
781
- refreshUserInfoFromServer() {
782
- this.danglIdentityClient.getUserInfo().subscribe({
783
- next: (serverUserInfo) => {
784
- if (serverUserInfo.userIsAuthenticated) {
785
- const userInfo = {
786
- deserializedToken: null,
787
- email: serverUserInfo.currentUserEmail,
788
- id: serverUserInfo.currentUserId,
789
- identiconId: serverUserInfo.currentUserIdenticonId,
790
- roles: [],
791
- claims: {},
792
- username: serverUserInfo.currentUserName,
793
- };
794
- serverUserInfo.userClaims.forEach((claim) => {
795
- if (claim.type === 'role') {
796
- userInfo.roles.push(claim.value);
797
- }
798
- else if (userInfo.claims[claim.type] === undefined) {
799
- userInfo.claims[claim.type] = [claim.value];
800
- }
801
- else {
802
- userInfo.claims[claim.type].push(claim.value);
803
- }
804
- });
805
- this.isAuthenticated.next(true);
806
- this.username.next(serverUserInfo.currentUserName);
807
- this.email.next(serverUserInfo.currentUserEmail);
808
- this.identiconId.next(serverUserInfo.currentUserIdenticonId);
809
- this.userInfo.next(userInfo);
810
- }
811
- else {
812
- this.isAuthenticated.next(false);
813
- this.username.next(null);
814
- this.email.next(null);
815
- this.identiconId.next(null);
816
- this.userInfo.next(null);
817
- }
818
- },
819
- });
820
- }
821
- refreshAuthenticationStatus(jwtToken) {
822
- if (jwtToken) {
823
- const isValidToken = jwtToken.expiresAt > new Date().getTime() / 1000;
824
- if (this.lastBroadcastAccessToken === jwtToken.accessToken) {
825
- return;
826
- }
827
- this.lastBroadcastAccessToken = jwtToken.accessToken;
828
- if (isValidToken) {
829
- this.isAuthenticated.next(true);
830
- const decodedToken = this.jwtHelperService.decodeToken(jwtToken.accessToken);
831
- this.username.next(decodedToken['name']);
832
- this.email.next(decodedToken['email']);
833
- this.identiconId.next(decodedToken['identicon_id']);
834
- const tokenClaims = {};
835
- for (const tokenProp in decodedToken) {
836
- if (decodedToken.hasOwnProperty(tokenProp)) {
837
- const property = decodedToken[tokenProp];
838
- if (typeof property === 'string') {
839
- if (tokenClaims[tokenProp] === undefined) {
840
- tokenClaims[tokenProp] = [];
841
- }
842
- tokenClaims[tokenProp].push(property);
843
- }
844
- }
845
- }
846
- this.userInfo.next({
847
- id: decodedToken['sub'],
848
- claims: tokenClaims,
849
- deserializedToken: decodedToken,
850
- email: decodedToken['email'],
851
- identiconId: decodedToken['identicon_id'],
852
- username: decodedToken['name'],
853
- roles: decodedToken['role'],
854
- });
855
- }
856
- else {
857
- this.isAuthenticated.next(false);
858
- this.jwtTokenService.refreshToken().subscribe(() => { });
859
- }
860
- }
861
- else {
862
- if (this.lastBroadcastAccessToken === null) {
863
- return;
864
- }
865
- this.lastBroadcastAccessToken = null;
866
- this.isAuthenticated.next(false);
867
- this.username.next(null);
868
- this.email.next(null);
869
- this.identiconId.next(null);
870
- this.userInfo.next(null);
871
- }
872
- }
873
- }
874
- AuthenticationMessenger.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: AuthenticationMessenger, deps: [{ token: JwtTokenService }, { token: DanglIdentityClient }], target: i0.ɵɵFactoryTarget.Injectable });
875
- AuthenticationMessenger.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: AuthenticationMessenger, providedIn: 'root' });
876
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: AuthenticationMessenger, decorators: [{
877
- type: Injectable,
878
- args: [{
879
- providedIn: 'root',
880
- }]
881
- }], ctorParameters: function () { return [{ type: JwtTokenService }, { type: DanglIdentityClient }]; } });
752
+ class AuthenticationMessenger {
753
+ constructor() {
754
+ this.jwtHelperService = new JwtHelperService();
755
+ this.$destroyed = new Subject();
756
+ this.isAuthenticated = new ReplaySubject(1);
757
+ this.username = new ReplaySubject(1);
758
+ this.email = new ReplaySubject(1);
759
+ this.identiconId = new ReplaySubject(1);
760
+ this.userInfo = new ReplaySubject(1);
761
+ this.tokenRefreshStarted = new Subject();
762
+ this.tokenRefreshFinished = new Subject();
763
+ this.jwtTokenService = inject(JwtTokenService);
764
+ this.danglIdentityClient = inject(DanglIdentityClient);
765
+ }
766
+ ngOnInit() {
767
+ this.jwtTokenService.tokenRefreshStarted
768
+ .pipe(takeUntil(this.$destroyed))
769
+ .subscribe(() => this.tokenRefreshStarted.next());
770
+ this.jwtTokenService.tokenRefreshFinished
771
+ .pipe(takeUntil(this.$destroyed))
772
+ .subscribe((successfulRefresh) => this.tokenRefreshFinished.next(successfulRefresh));
773
+ this.jwtTokenService.tokenStored
774
+ .pipe(takeUntil(this.$destroyed))
775
+ .subscribe((jwtToken) => this.refreshAuthenticationStatus(jwtToken));
776
+ this.jwtTokenService
777
+ .getToken()
778
+ .subscribe((token) => this.refreshAuthenticationStatus(token));
779
+ }
780
+ ngOnDestroy() {
781
+ this.isAuthenticated.complete();
782
+ this.username.complete();
783
+ this.email.complete();
784
+ this.identiconId.complete();
785
+ this.userInfo.complete();
786
+ this.tokenRefreshStarted.complete();
787
+ this.tokenRefreshFinished.complete();
788
+ this.$destroyed.next();
789
+ this.$destroyed.complete();
790
+ this.clearLogoutTimer();
791
+ }
792
+ refreshUserInfoFromServer() {
793
+ this.danglIdentityClient.getUserInfo().subscribe({
794
+ next: (serverUserInfo) => {
795
+ if (serverUserInfo.userIsAuthenticated) {
796
+ const userInfo = {
797
+ deserializedToken: null,
798
+ email: serverUserInfo.currentUserEmail,
799
+ id: serverUserInfo.currentUserId,
800
+ identiconId: serverUserInfo.currentUserIdenticonId,
801
+ roles: [],
802
+ claims: {},
803
+ username: serverUserInfo.currentUserName,
804
+ };
805
+ serverUserInfo.userClaims.forEach((claim) => {
806
+ if (claim.type === 'role') {
807
+ userInfo.roles.push(claim.value);
808
+ }
809
+ else if (userInfo.claims[claim.type] === undefined) {
810
+ userInfo.claims[claim.type] = [claim.value];
811
+ }
812
+ else {
813
+ userInfo.claims[claim.type].push(claim.value);
814
+ }
815
+ });
816
+ this.isAuthenticated.next(true);
817
+ this.username.next(serverUserInfo.currentUserName);
818
+ this.email.next(serverUserInfo.currentUserEmail);
819
+ this.identiconId.next(serverUserInfo.currentUserIdenticonId);
820
+ this.userInfo.next(userInfo);
821
+ }
822
+ else {
823
+ this.isAuthenticated.next(false);
824
+ this.username.next(null);
825
+ this.email.next(null);
826
+ this.identiconId.next(null);
827
+ this.userInfo.next(null);
828
+ }
829
+ },
830
+ });
831
+ }
832
+ refreshAuthenticationStatus(jwtToken) {
833
+ if (jwtToken) {
834
+ const isValidToken = jwtToken.expiresAt > new Date().getTime() / 1000;
835
+ if (this.lastBroadcastAccessToken === jwtToken.accessToken) {
836
+ return;
837
+ }
838
+ this.lastBroadcastAccessToken = jwtToken.accessToken;
839
+ if (isValidToken) {
840
+ this.isAuthenticated.next(true);
841
+ this.startTokenExpirationWatcher(jwtToken);
842
+ const decodedToken = this.jwtHelperService.decodeToken(jwtToken.accessToken);
843
+ this.username.next(decodedToken['name']);
844
+ this.email.next(decodedToken['email']);
845
+ this.identiconId.next(decodedToken['identicon_id']);
846
+ const tokenClaims = {};
847
+ for (const tokenProp in decodedToken) {
848
+ if (decodedToken.hasOwnProperty(tokenProp)) {
849
+ const property = decodedToken[tokenProp];
850
+ if (typeof property === 'string') {
851
+ if (tokenClaims[tokenProp] === undefined) {
852
+ tokenClaims[tokenProp] = [];
853
+ }
854
+ tokenClaims[tokenProp].push(property);
855
+ }
856
+ }
857
+ }
858
+ this.userInfo.next({
859
+ id: decodedToken['sub'],
860
+ claims: tokenClaims,
861
+ deserializedToken: decodedToken,
862
+ email: decodedToken['email'],
863
+ identiconId: decodedToken['identicon_id'],
864
+ username: decodedToken['name'],
865
+ roles: decodedToken['role'],
866
+ });
867
+ }
868
+ else {
869
+ this.isAuthenticated.next(false);
870
+ this.jwtTokenService.refreshToken().subscribe(() => { });
871
+ }
872
+ }
873
+ else {
874
+ if (this.lastBroadcastAccessToken === null) {
875
+ return;
876
+ }
877
+ this.lastBroadcastAccessToken = null;
878
+ this.isAuthenticated.next(false);
879
+ this.username.next(null);
880
+ this.email.next(null);
881
+ this.identiconId.next(null);
882
+ this.userInfo.next(null);
883
+ }
884
+ }
885
+ startTokenExpirationWatcher(jwtToken) {
886
+ const expirationTime = jwtToken.expiresAt * 1000;
887
+ const currentTime = Date.now();
888
+ const timeUntilExpiration = expirationTime - currentTime;
889
+ this.clearLogoutTimer();
890
+ if (timeUntilExpiration > 0) {
891
+ this.expirationSubscription = timer(timeUntilExpiration).subscribe(() => {
892
+ this.isAuthenticated.next(false);
893
+ });
894
+ }
895
+ else {
896
+ this.isAuthenticated.next(false);
897
+ }
898
+ }
899
+ clearLogoutTimer() {
900
+ if (this.expirationSubscription) {
901
+ this.expirationSubscription.unsubscribe();
902
+ this.expirationSubscription = undefined;
903
+ }
904
+ }
905
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: AuthenticationMessenger, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
906
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: AuthenticationMessenger, providedIn: 'root' }); }
907
+ }
908
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: AuthenticationMessenger, decorators: [{
909
+ type: Injectable,
910
+ args: [{
911
+ providedIn: 'root',
912
+ }]
913
+ }], ctorParameters: () => [] });
882
914
 
883
- /*
884
- * Public API Surface of angular-dangl-identity-client
915
+ /*
916
+ * Public API Surface of angular-dangl-identity-client
885
917
  */
886
918
 
887
- /**
888
- * Generated bundle index. Do not edit.
919
+ /**
920
+ * Generated bundle index. Do not edit.
889
921
  */
890
922
 
891
923
  export { AuthenticationMessenger, AuthenticationService, DANGL_IDENTITY_CLIENT_API_BASE_URL, DANGL_IDENTITY_REQUEST_VALIDATOR, DanglIdentityClient, DanglIdentityModule, HttpStatusCode, JwtInterceptorService, JwtTokenService, ResponseErrorType, SwaggerException };