@dangl/angular-dangl-identity-client 4.0.0-pullrequest0003-0010 → 4.0.1-beta0003

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 (34) hide show
  1. package/README.md +1 -1
  2. package/api-client.d.ts +3 -0
  3. package/dangl-angular-dangl-identity-client.d.ts +1 -0
  4. package/dangl-identity.module.d.ts +5 -0
  5. package/esm2020/api-client.mjs +482 -0
  6. package/{esm2015/dangl-angular-dangl-identity-client.js → esm2020/dangl-angular-dangl-identity-client.mjs} +0 -0
  7. package/esm2020/dangl-identity.module.mjs +21 -0
  8. package/{esm2015/interceptors/dangl-identity-request-validator.js → esm2020/interceptors/dangl-identity-request-validator.mjs} +0 -0
  9. package/esm2020/interceptors/jwt-interceptor.service.mjs +47 -0
  10. package/esm2020/messengers/authentication.messenger.mjs +83 -0
  11. package/{esm2015/models/jwt-storage.js → esm2020/models/jwt-storage.mjs} +0 -0
  12. package/{esm2015/models/user-info.js → esm2020/models/user-info.mjs} +0 -0
  13. package/{esm2015/public_api.js → esm2020/public_api.mjs} +0 -0
  14. package/esm2020/services/authentication.service.mjs +41 -0
  15. package/esm2020/services/jwt-token.service.mjs +95 -0
  16. package/fesm2015/dangl-angular-dangl-identity-client.mjs +754 -0
  17. package/fesm2015/dangl-angular-dangl-identity-client.mjs.map +1 -0
  18. package/{fesm2015/dangl-angular-dangl-identity-client.js → fesm2020/dangl-angular-dangl-identity-client.mjs} +66 -55
  19. package/fesm2020/dangl-angular-dangl-identity-client.mjs.map +1 -0
  20. package/interceptors/jwt-interceptor.service.d.ts +3 -0
  21. package/messengers/authentication.messenger.d.ts +3 -0
  22. package/package.json +21 -9
  23. package/services/authentication.service.d.ts +3 -0
  24. package/services/jwt-token.service.d.ts +3 -0
  25. package/bundles/dangl-angular-dangl-identity-client.umd.js +0 -1179
  26. package/bundles/dangl-angular-dangl-identity-client.umd.js.map +0 -1
  27. package/dangl-angular-dangl-identity-client.metadata.json +0 -1
  28. package/esm2015/api-client.js +0 -476
  29. package/esm2015/dangl-identity.module.js +0 -14
  30. package/esm2015/interceptors/jwt-interceptor.service.js +0 -43
  31. package/esm2015/messengers/authentication.messenger.js +0 -85
  32. package/esm2015/services/authentication.service.js +0 -45
  33. package/esm2015/services/jwt-token.service.js +0 -97
  34. package/fesm2015/dangl-angular-dangl-identity-client.js.map +0 -1
@@ -0,0 +1,754 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, Injectable, Inject, Optional, NgModule } from '@angular/core';
3
+ import * as i1 from '@angular/common/http';
4
+ import { HttpHeaders, HttpResponseBase, HttpResponse, HttpClient, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
5
+ import { mergeMap, catchError, first, tap, map } from 'rxjs/operators';
6
+ import { throwError, Observable, of, Subject, ReplaySubject } from 'rxjs';
7
+ import { JwtHelperService } from '@auth0/angular-jwt';
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 !== undefined && baseUrl !== null ? 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 !== 200 && status !== 204) {
345
+ return blobToText(responseBlob).pipe(mergeMap(_responseText => {
346
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
347
+ }));
348
+ }
349
+ return of(null);
350
+ }
351
+ }
352
+ DanglIdentityClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: DanglIdentityClient, deps: [{ token: HttpClient }, { token: DANGL_IDENTITY_CLIENT_API_BASE_URL, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
353
+ DanglIdentityClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: DanglIdentityClient, providedIn: 'root' });
354
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: DanglIdentityClient, decorators: [{
355
+ type: Injectable,
356
+ args: [{
357
+ providedIn: 'root'
358
+ }]
359
+ }], ctorParameters: function () {
360
+ return [{ type: i1.HttpClient, decorators: [{
361
+ type: Inject,
362
+ args: [HttpClient]
363
+ }] }, { type: undefined, decorators: [{
364
+ type: Optional
365
+ }, {
366
+ type: Inject,
367
+ args: [DANGL_IDENTITY_CLIENT_API_BASE_URL]
368
+ }] }];
369
+ } });
370
+ var HttpStatusCode;
371
+ (function (HttpStatusCode) {
372
+ HttpStatusCode["Continue"] = "Continue";
373
+ HttpStatusCode["SwitchingProtocols"] = "SwitchingProtocols";
374
+ HttpStatusCode["Processing"] = "Processing";
375
+ HttpStatusCode["EarlyHints"] = "EarlyHints";
376
+ HttpStatusCode["OK"] = "OK";
377
+ HttpStatusCode["Created"] = "Created";
378
+ HttpStatusCode["Accepted"] = "Accepted";
379
+ HttpStatusCode["NonAuthoritativeInformation"] = "NonAuthoritativeInformation";
380
+ HttpStatusCode["NoContent"] = "NoContent";
381
+ HttpStatusCode["ResetContent"] = "ResetContent";
382
+ HttpStatusCode["PartialContent"] = "PartialContent";
383
+ HttpStatusCode["MultiStatus"] = "MultiStatus";
384
+ HttpStatusCode["AlreadyReported"] = "AlreadyReported";
385
+ HttpStatusCode["IMUsed"] = "IMUsed";
386
+ HttpStatusCode["MultipleChoices"] = "Ambiguous";
387
+ HttpStatusCode["Ambiguous"] = "Moved";
388
+ HttpStatusCode["MovedPermanently"] = "Redirect";
389
+ HttpStatusCode["Moved"] = "RedirectMethod";
390
+ HttpStatusCode["Found"] = "NotModified";
391
+ HttpStatusCode["Redirect"] = "UseProxy";
392
+ HttpStatusCode["SeeOther"] = "Unused";
393
+ HttpStatusCode["RedirectMethod"] = "TemporaryRedirect";
394
+ HttpStatusCode["NotModified"] = "PermanentRedirect";
395
+ HttpStatusCode["UseProxy"] = "BadRequest";
396
+ HttpStatusCode["Unused"] = "Unauthorized";
397
+ HttpStatusCode["TemporaryRedirect"] = "PaymentRequired";
398
+ HttpStatusCode["RedirectKeepVerb"] = "Forbidden";
399
+ HttpStatusCode["PermanentRedirect"] = "NotFound";
400
+ HttpStatusCode["BadRequest"] = "MethodNotAllowed";
401
+ HttpStatusCode["Unauthorized"] = "NotAcceptable";
402
+ HttpStatusCode["PaymentRequired"] = "ProxyAuthenticationRequired";
403
+ HttpStatusCode["Forbidden"] = "RequestTimeout";
404
+ HttpStatusCode["NotFound"] = "Conflict";
405
+ HttpStatusCode["MethodNotAllowed"] = "Gone";
406
+ HttpStatusCode["NotAcceptable"] = "LengthRequired";
407
+ HttpStatusCode["ProxyAuthenticationRequired"] = "PreconditionFailed";
408
+ HttpStatusCode["RequestTimeout"] = "RequestEntityTooLarge";
409
+ HttpStatusCode["Conflict"] = "RequestUriTooLong";
410
+ HttpStatusCode["Gone"] = "UnsupportedMediaType";
411
+ HttpStatusCode["LengthRequired"] = "RequestedRangeNotSatisfiable";
412
+ HttpStatusCode["PreconditionFailed"] = "ExpectationFailed";
413
+ HttpStatusCode["RequestEntityTooLarge"] = "MisdirectedRequest";
414
+ HttpStatusCode["RequestUriTooLong"] = "UnprocessableEntity";
415
+ HttpStatusCode["UnsupportedMediaType"] = "Locked";
416
+ HttpStatusCode["RequestedRangeNotSatisfiable"] = "FailedDependency";
417
+ HttpStatusCode["ExpectationFailed"] = "UpgradeRequired";
418
+ HttpStatusCode["MisdirectedRequest"] = "PreconditionRequired";
419
+ HttpStatusCode["UnprocessableEntity"] = "TooManyRequests";
420
+ HttpStatusCode["Locked"] = "RequestHeaderFieldsTooLarge";
421
+ HttpStatusCode["FailedDependency"] = "UnavailableForLegalReasons";
422
+ HttpStatusCode["UpgradeRequired"] = "InternalServerError";
423
+ HttpStatusCode["PreconditionRequired"] = "NotImplemented";
424
+ HttpStatusCode["TooManyRequests"] = "BadGateway";
425
+ HttpStatusCode["RequestHeaderFieldsTooLarge"] = "ServiceUnavailable";
426
+ HttpStatusCode["UnavailableForLegalReasons"] = "GatewayTimeout";
427
+ HttpStatusCode["InternalServerError"] = "HttpVersionNotSupported";
428
+ HttpStatusCode["NotImplemented"] = "VariantAlsoNegotiates";
429
+ HttpStatusCode["BadGateway"] = "InsufficientStorage";
430
+ HttpStatusCode["ServiceUnavailable"] = "LoopDetected";
431
+ HttpStatusCode["GatewayTimeout"] = "NotExtended";
432
+ HttpStatusCode["HttpVersionNotSupported"] = "NetworkAuthenticationRequired";
433
+ })(HttpStatusCode || (HttpStatusCode = {}));
434
+ /** Various reasons for a protocol endpoint error */
435
+ var ResponseErrorType;
436
+ (function (ResponseErrorType) {
437
+ ResponseErrorType["None"] = "None";
438
+ ResponseErrorType["Protocol"] = "Protocol";
439
+ ResponseErrorType["Http"] = "Http";
440
+ ResponseErrorType["Exception"] = "Exception";
441
+ ResponseErrorType["PolicyViolation"] = "PolicyViolation";
442
+ })(ResponseErrorType || (ResponseErrorType = {}));
443
+ class SwaggerException extends Error {
444
+ constructor(message, status, response, headers, result) {
445
+ super();
446
+ this.isSwaggerException = true;
447
+ this.message = message;
448
+ this.status = status;
449
+ this.response = response;
450
+ this.headers = headers;
451
+ this.result = result;
452
+ }
453
+ static isSwaggerException(obj) {
454
+ return obj.isSwaggerException === true;
455
+ }
456
+ }
457
+ function throwException(message, status, response, headers, result) {
458
+ if (result !== null && result !== undefined)
459
+ return throwError(result);
460
+ else
461
+ return throwError(new SwaggerException(message, status, response, headers, null));
462
+ }
463
+ function blobToText(blob) {
464
+ return new Observable((observer) => {
465
+ if (!blob) {
466
+ observer.next("");
467
+ observer.complete();
468
+ }
469
+ else {
470
+ let reader = new FileReader();
471
+ reader.onload = event => {
472
+ observer.next(event.target.result);
473
+ observer.complete();
474
+ };
475
+ reader.readAsText(blob);
476
+ }
477
+ });
478
+ }
479
+
480
+ class JwtTokenService {
481
+ constructor(danglIdentityClient) {
482
+ this.danglIdentityClient = danglIdentityClient;
483
+ this.storage_identifier = "dangl_identity_integration_jwt_token";
484
+ this.isRefreshing = false;
485
+ this.refreshTokenSource = new Subject();
486
+ this.tokenStoredSource = new ReplaySubject(1);
487
+ this.tokenStored = this.tokenStoredSource.asObservable();
488
+ this.tokenRefreshStartedSource = new Subject();
489
+ this.tokenRefreshStarted = this.tokenRefreshStartedSource.asObservable();
490
+ this.tokenRefreshFinishedSource = new Subject();
491
+ this.tokenRefreshFinished = this.tokenRefreshFinishedSource.asObservable();
492
+ }
493
+ deleteToken() {
494
+ localStorage.removeItem(this.storage_identifier);
495
+ this.tokenStoredSource.next(null);
496
+ }
497
+ storeCustomToken(tokenToStore) {
498
+ localStorage.setItem(this.storage_identifier, JSON.stringify(tokenToStore));
499
+ this.tokenStoredSource.next(tokenToStore);
500
+ }
501
+ storeToken(token) {
502
+ const tokenToStore = this.transformTokenResponse(token);
503
+ localStorage.setItem(this.storage_identifier, JSON.stringify(tokenToStore));
504
+ this.tokenStoredSource.next(tokenToStore);
505
+ }
506
+ getTokenFromStorage() {
507
+ const storedString = localStorage.getItem(this.storage_identifier);
508
+ if (storedString) {
509
+ const storedToken = JSON.parse(storedString);
510
+ return storedToken;
511
+ }
512
+ return null;
513
+ }
514
+ refreshToken() {
515
+ if (this.isRefreshing) {
516
+ return this.refreshTokenSource.pipe(first());
517
+ }
518
+ this.isRefreshing = true;
519
+ this.tokenRefreshStartedSource.next();
520
+ const refreshToken = this.getTokenFromStorage().refreshToken;
521
+ if (!refreshToken) {
522
+ this.isRefreshing = false;
523
+ return of(null);
524
+ }
525
+ this.danglIdentityClient
526
+ .refreshToken({
527
+ refreshToken: refreshToken,
528
+ })
529
+ .pipe(tap((r) => this.storeToken(r)), map((r) => this.transformTokenResponse(r)))
530
+ .subscribe((refreshTokenResponse) => {
531
+ this.isRefreshing = false;
532
+ this.tokenRefreshFinishedSource.next(true);
533
+ this.refreshTokenSource.next(refreshTokenResponse);
534
+ }, (error) => {
535
+ this.isRefreshing = false;
536
+ this.tokenRefreshFinishedSource.next(false);
537
+ this.refreshTokenSource.next(null);
538
+ console.error("Internal error while refreshing Dangl.Identity token", error);
539
+ });
540
+ return this.refreshTokenSource.pipe(first());
541
+ }
542
+ getToken() {
543
+ const token = this.getTokenFromStorage();
544
+ if (!token) {
545
+ return of(null);
546
+ }
547
+ const isValidToken = token.expiresAt > new Date().getTime() / 1000;
548
+ if (isValidToken) {
549
+ return of(token);
550
+ }
551
+ return this.refreshToken();
552
+ }
553
+ transformTokenResponse(token) {
554
+ return {
555
+ accessToken: token.accessToken,
556
+ refreshToken: token.refreshToken,
557
+ expiresAt: new Date().getTime() / 1000 + token.expiresIn,
558
+ };
559
+ }
560
+ }
561
+ JwtTokenService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: JwtTokenService, deps: [{ token: DanglIdentityClient }], target: i0.ɵɵFactoryTarget.Injectable });
562
+ JwtTokenService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: JwtTokenService, providedIn: "root" });
563
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: JwtTokenService, decorators: [{
564
+ type: Injectable,
565
+ args: [{
566
+ providedIn: "root",
567
+ }]
568
+ }], ctorParameters: function () { return [{ type: DanglIdentityClient }]; } });
569
+
570
+ const DANGL_IDENTITY_REQUEST_VALIDATOR = new InjectionToken("Validator to decide whether to include JWT tokens in requests");
571
+ class JwtInterceptorService {
572
+ constructor(jwtTokenService, requestValidator) {
573
+ this.jwtTokenService = jwtTokenService;
574
+ this.requestValidator = requestValidator;
575
+ }
576
+ intercept(request, next) {
577
+ if (request.url.startsWith("/identity")) {
578
+ // Requests to the authentication endpoint should not be intercepted
579
+ return next.handle(request.clone());
580
+ }
581
+ if (this.requestValidator &&
582
+ !this.requestValidator.validateRequest(request)) {
583
+ // In case a request validator is provided but doesn't return true for the
584
+ // current request, we're not appending a token
585
+ return next.handle(request);
586
+ }
587
+ return this.jwtTokenService
588
+ .getToken()
589
+ .pipe(mergeMap((f) => next.handle(this.getHttpRequestWithToken(request, f && f.accessToken))));
590
+ }
591
+ getHttpRequestWithToken(request, token) {
592
+ if (token) {
593
+ return request.clone({
594
+ setHeaders: {
595
+ Authorization: `Bearer ${token}`,
596
+ },
597
+ });
598
+ }
599
+ return request.clone();
600
+ }
601
+ }
602
+ JwtInterceptorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: JwtInterceptorService, deps: [{ token: JwtTokenService }, { token: DANGL_IDENTITY_REQUEST_VALIDATOR, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
603
+ JwtInterceptorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: JwtInterceptorService });
604
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: JwtInterceptorService, decorators: [{
605
+ type: Injectable
606
+ }], ctorParameters: function () {
607
+ return [{ type: JwtTokenService }, { type: undefined, decorators: [{
608
+ type: Optional
609
+ }, {
610
+ type: Inject,
611
+ args: [DANGL_IDENTITY_REQUEST_VALIDATOR]
612
+ }] }];
613
+ } });
614
+
615
+ class DanglIdentityModule {
616
+ }
617
+ DanglIdentityModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: DanglIdentityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
618
+ DanglIdentityModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: DanglIdentityModule, imports: [HttpClientModule] });
619
+ DanglIdentityModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: DanglIdentityModule, providers: [{ provide: HTTP_INTERCEPTORS, useClass: JwtInterceptorService, multi: true }], imports: [[
620
+ HttpClientModule
621
+ ]] });
622
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: DanglIdentityModule, decorators: [{
623
+ type: NgModule,
624
+ args: [{
625
+ imports: [
626
+ HttpClientModule
627
+ ],
628
+ providers: [{ provide: HTTP_INTERCEPTORS, useClass: JwtInterceptorService, multi: true }]
629
+ }]
630
+ }] });
631
+
632
+ class AuthenticationService {
633
+ constructor(danglIdentityClient, jwtTokenService) {
634
+ this.danglIdentityClient = danglIdentityClient;
635
+ this.jwtTokenService = jwtTokenService;
636
+ }
637
+ loginWithToken(identifier, password) {
638
+ return this.danglIdentityClient
639
+ .loginAndReturnToken({
640
+ identifier: identifier,
641
+ password: password
642
+ })
643
+ .pipe(map(r => this.storeJwtTokenIfValid(r)), catchError(e => of(false)));
644
+ }
645
+ storeJwtTokenIfValid(token) {
646
+ if (!token.accessToken
647
+ || !token.refreshToken
648
+ || !token.expiresIn) {
649
+ return false;
650
+ }
651
+ this.jwtTokenService.storeToken(token);
652
+ return true;
653
+ }
654
+ logout() {
655
+ this.jwtTokenService.deleteToken();
656
+ }
657
+ }
658
+ AuthenticationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: AuthenticationService, deps: [{ token: DanglIdentityClient }, { token: JwtTokenService }], target: i0.ɵɵFactoryTarget.Injectable });
659
+ AuthenticationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: AuthenticationService, providedIn: 'root' });
660
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: AuthenticationService, decorators: [{
661
+ type: Injectable,
662
+ args: [{
663
+ providedIn: 'root'
664
+ }]
665
+ }], ctorParameters: function () { return [{ type: DanglIdentityClient }, { type: JwtTokenService }]; } });
666
+
667
+ class AuthenticationMessenger {
668
+ constructor(jwtTokenService) {
669
+ this.jwtTokenService = jwtTokenService;
670
+ this.jwtHelperService = new JwtHelperService();
671
+ this.isAuthenticated = new ReplaySubject(1);
672
+ this.username = new ReplaySubject(1);
673
+ this.email = new ReplaySubject(1);
674
+ this.identiconId = new ReplaySubject(1);
675
+ this.userInfo = new ReplaySubject(1);
676
+ this.tokenRefreshStarted = new Subject();
677
+ this.tokenRefreshFinished = new Subject();
678
+ jwtTokenService.tokenRefreshStarted.subscribe(() => this.tokenRefreshStarted.next());
679
+ jwtTokenService.tokenRefreshFinished.subscribe(successfulRefresh => this.tokenRefreshFinished.next(successfulRefresh));
680
+ jwtTokenService.tokenStored.subscribe(jwtToken => this.refreshAuthenticationStatus(jwtToken));
681
+ jwtTokenService.getToken()
682
+ .subscribe(token => this.refreshAuthenticationStatus(token));
683
+ }
684
+ refreshAuthenticationStatus(jwtToken) {
685
+ if (jwtToken) {
686
+ const isValidToken = jwtToken.expiresAt > (new Date().getTime() / 1000);
687
+ if (this.lastBroadcastAccessToken === jwtToken.accessToken) {
688
+ return;
689
+ }
690
+ this.lastBroadcastAccessToken = jwtToken.accessToken;
691
+ if (isValidToken) {
692
+ this.isAuthenticated.next(true);
693
+ const decodedToken = this.jwtHelperService.decodeToken(jwtToken.accessToken);
694
+ this.username.next(decodedToken['name']);
695
+ this.email.next(decodedToken['email']);
696
+ this.identiconId.next(decodedToken['identicon_id']);
697
+ const tokenClaims = {};
698
+ for (const tokenProp in decodedToken) {
699
+ if (decodedToken.hasOwnProperty(tokenProp)) {
700
+ const property = decodedToken[tokenProp];
701
+ if (typeof property === 'string') {
702
+ tokenClaims[tokenProp] = property;
703
+ }
704
+ }
705
+ }
706
+ this.userInfo.next({
707
+ id: decodedToken['sub'],
708
+ claims: tokenClaims,
709
+ deserializedToken: decodedToken,
710
+ email: decodedToken['email'],
711
+ identiconId: decodedToken['identicon_id'],
712
+ username: decodedToken['name'],
713
+ roles: decodedToken['role']
714
+ });
715
+ }
716
+ else {
717
+ this.isAuthenticated.next(false);
718
+ this.jwtTokenService
719
+ .refreshToken()
720
+ .subscribe(() => { });
721
+ }
722
+ }
723
+ else {
724
+ if (this.lastBroadcastAccessToken === null) {
725
+ return;
726
+ }
727
+ this.lastBroadcastAccessToken = null;
728
+ this.isAuthenticated.next(false);
729
+ this.username.next(null);
730
+ this.email.next(null);
731
+ this.identiconId.next(null);
732
+ this.userInfo.next(null);
733
+ }
734
+ }
735
+ }
736
+ AuthenticationMessenger.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: AuthenticationMessenger, deps: [{ token: JwtTokenService }], target: i0.ɵɵFactoryTarget.Injectable });
737
+ AuthenticationMessenger.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: AuthenticationMessenger, providedIn: 'root' });
738
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.6", ngImport: i0, type: AuthenticationMessenger, decorators: [{
739
+ type: Injectable,
740
+ args: [{
741
+ providedIn: 'root'
742
+ }]
743
+ }], ctorParameters: function () { return [{ type: JwtTokenService }]; } });
744
+
745
+ /*
746
+ * Public API Surface of angular-dangl-identity-client
747
+ */
748
+
749
+ /**
750
+ * Generated bundle index. Do not edit.
751
+ */
752
+
753
+ export { AuthenticationMessenger, AuthenticationService, DANGL_IDENTITY_CLIENT_API_BASE_URL, DANGL_IDENTITY_REQUEST_VALIDATOR, DanglIdentityClient, DanglIdentityModule, HttpStatusCode, JwtInterceptorService, JwtTokenService, ResponseErrorType, SwaggerException };
754
+ //# sourceMappingURL=dangl-angular-dangl-identity-client.mjs.map