@igo2/auth 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/router'), require('rxjs/operators'), require('@angular/common/http'), require('rxjs'), require('ts-cacheable'), require('@igo2/utils'), require('jwt-decode'), require('@igo2/core'), require('@angular/common'), require('@azure/msal-angular'), require('@azure/msal-browser'), require('@angular/material/button'), require('@angular/material/icon'), require('@ngx-translate/core'), require('@angular/forms'), require('@angular/material/form-field'), require('@angular/material/input'), require('ts-md5')) :
3
3
  typeof define === 'function' && define.amd ? define('@igo2/auth', ['exports', '@angular/core', '@angular/router', 'rxjs/operators', '@angular/common/http', 'rxjs', 'ts-cacheable', '@igo2/utils', 'jwt-decode', '@igo2/core', '@angular/common', '@azure/msal-angular', '@azure/msal-browser', '@angular/material/button', '@angular/material/icon', '@ngx-translate/core', '@angular/forms', '@angular/material/form-field', '@angular/material/input', 'ts-md5'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.igo2 = global.igo2 || {}, global.igo2.auth = {}), global.ng.core, global.ng.router, global.rxjs.operators, global.ng.common.http, global.rxjs, global.tsCacheable, global.utils, global.jwt, global.core, global.ng.common, global['msal-angular'], global['msal-browser'], global.ng.material.button, global.ng.material.icon, global['ngxt-core'], global.ng.forms, global.ng.material.formField, global.ng.material.input, global.tsMd5));
5
- }(this, (function (exports, i0, i3, operators, i1, rxjs, tsCacheable, utils, jwtDecode, i2, i1$1, i3$1, msalBrowser, i4, i5, i6, i3$2, i4$1, i5$1, tsMd5) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.igo2 = global.igo2 || {}, global.igo2.auth = {}), global.ng.core, global.ng.router, global.rxjs.operators, global.ng.common.http, global.rxjs, global.tsCacheable, global.utils, global.jwt, global.core, global.ng.common, global["msal-angular"], global["msal-browser"], global.ng.material.button, global.ng.material.icon, global["ngxt-core"], global.ng.forms, global.ng.material.formField, global.ng.material.input, global.tsMd5));
5
+ })(this, (function (exports, i0, i3, operators, i1, rxjs, tsCacheable, utils, jwtDecode, i2, i1$1, i3$1, msalBrowser, i4, i5, i6, i3$2, i4$1, i5$1, tsMd5) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -15,14 +15,12 @@
15
15
  var d = Object.getOwnPropertyDescriptor(e, k);
16
16
  Object.defineProperty(n, k, d.get ? d : {
17
17
  enumerable: true,
18
- get: function () {
19
- return e[k];
20
- }
18
+ get: function () { return e[k]; }
21
19
  });
22
20
  }
23
21
  });
24
22
  }
25
- n['default'] = e;
23
+ n["default"] = e;
26
24
  return Object.freeze(n);
27
25
  }
28
26
 
@@ -58,7 +56,7 @@
58
56
  if (!token) {
59
57
  return;
60
58
  }
61
- return jwtDecode__default['default'](token);
59
+ return jwtDecode__default["default"](token);
62
60
  };
63
61
  TokenService.prototype.isExpired = function () {
64
62
  var jwt = this.decode();
@@ -1697,9 +1695,22 @@
1697
1695
  enumerable: false,
1698
1696
  configurable: true
1699
1697
  });
1698
+ Object.defineProperty(AuthInterceptor.prototype, "hostsWithAuthByKey", {
1699
+ get: function () {
1700
+ return this.config.getConfig('auth.hostsByKey') || [];
1701
+ },
1702
+ enumerable: false,
1703
+ configurable: true
1704
+ });
1700
1705
  AuthInterceptor.prototype.intercept = function (originalReq, next) {
1701
1706
  var withCredentials = this.handleHostsWithCredentials(originalReq.url);
1702
1707
  var req = originalReq.clone();
1708
+ var hostWithKey = this.handleHostsAuthByKey(originalReq.url);
1709
+ if (hostWithKey) {
1710
+ req = req.clone({
1711
+ params: req.params.set(hostWithKey.key, hostWithKey.value)
1712
+ });
1713
+ }
1703
1714
  if (withCredentials) {
1704
1715
  req = originalReq.clone({
1705
1716
  withCredentials: withCredentials
@@ -1752,6 +1763,21 @@
1752
1763
  xhr.setRequestHeader('Authorization', 'Bearer ' + token);
1753
1764
  return true;
1754
1765
  };
1766
+ AuthInterceptor.prototype.alterUrlWithKeyAuth = function (url) {
1767
+ var hostWithKey = this.handleHostsAuthByKey(url);
1768
+ var interceptedUrl = url;
1769
+ if (hostWithKey) {
1770
+ var urlDecomposed = interceptedUrl.split(/[?&]/);
1771
+ var urlWithKeyAdded = urlDecomposed.shift();
1772
+ var paramsToKeep = urlDecomposed.filter(function (p) { return p.length !== 0; });
1773
+ paramsToKeep.push(hostWithKey.key + "=" + hostWithKey.value);
1774
+ if (paramsToKeep.length) {
1775
+ urlWithKeyAdded += '?' + paramsToKeep.join('&');
1776
+ }
1777
+ return urlWithKeyAdded;
1778
+ }
1779
+ return;
1780
+ };
1755
1781
  AuthInterceptor.prototype.handleHostsWithCredentials = function (reqUrl) {
1756
1782
  var e_1, _a;
1757
1783
  var withCredentials = false;
@@ -1774,6 +1800,28 @@
1774
1800
  }
1775
1801
  return withCredentials;
1776
1802
  };
1803
+ AuthInterceptor.prototype.handleHostsAuthByKey = function (reqUrl) {
1804
+ var e_2, _a;
1805
+ var hostWithKey;
1806
+ try {
1807
+ for (var _b = __values(this.hostsWithAuthByKey), _c = _b.next(); !_c.done; _c = _b.next()) {
1808
+ var hostWithAuthByKey = _c.value;
1809
+ var domainRegex = new RegExp(hostWithAuthByKey.domainRegFilters);
1810
+ if (domainRegex.test(reqUrl)) {
1811
+ hostWithKey = { key: hostWithAuthByKey.keyProperty, value: hostWithAuthByKey.keyValue };
1812
+ break;
1813
+ }
1814
+ }
1815
+ }
1816
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1817
+ finally {
1818
+ try {
1819
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1820
+ }
1821
+ finally { if (e_2) throw e_2.error; }
1822
+ }
1823
+ return hostWithKey;
1824
+ };
1777
1825
  AuthInterceptor.prototype.refreshToken = function () {
1778
1826
  var _this = this;
1779
1827
  var jwt = this.tokenService.decode();
@@ -2149,5 +2197,5 @@
2149
2197
 
2150
2198
  Object.defineProperty(exports, '__esModule', { value: true });
2151
2199
 
2152
- })));
2200
+ }));
2153
2201
  //# sourceMappingURL=igo2-auth.umd.js.map