@axa-fr/react-oidc 6.24.27-beta929 → 6.25.0-alpha939

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 (264) hide show
  1. package/bin/post-install.js +35 -0
  2. package/dist/FetchToken.d.ts +2 -3
  3. package/dist/FetchToken.d.ts.map +1 -1
  4. package/dist/OidcProvider.d.ts +4 -5
  5. package/dist/OidcProvider.d.ts.map +1 -1
  6. package/dist/OidcSecure.d.ts +3 -3
  7. package/dist/OidcSecure.d.ts.map +1 -1
  8. package/dist/OidcServiceWorker.js +559 -0
  9. package/{service_worker → dist}/OidcTrustedDomains.js +4 -5
  10. package/dist/ReactOidc.d.ts +4 -4
  11. package/dist/ReactOidc.d.ts.map +1 -1
  12. package/dist/User.d.ts +2 -2
  13. package/dist/User.d.ts.map +1 -1
  14. package/dist/core/default-component/AuthenticateError.component.d.ts.map +1 -1
  15. package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
  16. package/dist/core/default-component/Callback.component.d.ts.map +1 -1
  17. package/dist/core/default-component/Loading.component.d.ts.map +1 -1
  18. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
  19. package/dist/core/default-component/SessionLost.component.d.ts.map +1 -1
  20. package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
  21. package/dist/core/default-component/SilentLogin.component.d.ts.map +1 -1
  22. package/dist/core/default-component/index.d.ts.map +1 -1
  23. package/dist/core/routes/OidcRoutes.d.ts +1 -1
  24. package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
  25. package/dist/core/routes/index.d.ts +3 -0
  26. package/dist/core/routes/index.d.ts.map +1 -0
  27. package/dist/core/routes/withRouter.d.ts +4 -4
  28. package/dist/core/routes/withRouter.d.ts.map +1 -1
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +964 -21
  32. package/dist/index.umd.cjs +27 -0
  33. package/package.json +37 -43
  34. package/src/{oidc/FetchToken.tsx → FetchToken.tsx} +14 -16
  35. package/src/{oidc/OidcProvider.tsx → OidcProvider.tsx} +40 -42
  36. package/src/{oidc/OidcSecure.tsx → OidcSecure.tsx} +1 -3
  37. package/src/{oidc/ReactOidc.tsx → ReactOidc.tsx} +1 -3
  38. package/src/{oidc/User.ts → User.ts} +1 -2
  39. package/src/{oidc/core → core}/default-component/AuthenticateError.component.tsx +0 -1
  40. package/src/{oidc/core → core}/default-component/Authenticating.component.tsx +0 -1
  41. package/src/{oidc/core → core}/default-component/Callback.component.tsx +2 -2
  42. package/src/{oidc/core → core}/default-component/Loading.component.tsx +0 -1
  43. package/src/{oidc/core → core}/default-component/ServiceWorkerNotSupported.component.tsx +0 -1
  44. package/src/{oidc/core → core}/default-component/SessionLost.component.tsx +1 -1
  45. package/src/{oidc/core → core}/default-component/SilentCallback.component.tsx +1 -2
  46. package/src/{oidc/core → core}/default-component/SilentLogin.component.tsx +1 -3
  47. package/src/{oidc/core → core}/routes/OidcRoutes.spec.tsx +3 -2
  48. package/src/{oidc/core → core}/routes/OidcRoutes.tsx +6 -6
  49. package/src/{oidc/core → core}/routes/withRouter.spec.tsx +3 -5
  50. package/src/{oidc/index.ts → index.ts} +7 -2
  51. package/bin/copy.cjs +0 -43
  52. package/dist/FetchToken.js +0 -59
  53. package/dist/FetchToken.js.map +0 -1
  54. package/dist/OidcProvider.js +0 -134
  55. package/dist/OidcProvider.js.map +0 -1
  56. package/dist/OidcSecure.js +0 -25
  57. package/dist/OidcSecure.js.map +0 -1
  58. package/dist/ReactOidc.js +0 -156
  59. package/dist/ReactOidc.js.map +0 -1
  60. package/dist/User.js +0 -42
  61. package/dist/User.js.map +0 -1
  62. package/dist/core/default-component/AuthenticateError.component.js +0 -6
  63. package/dist/core/default-component/AuthenticateError.component.js.map +0 -1
  64. package/dist/core/default-component/Authenticating.component.js +0 -6
  65. package/dist/core/default-component/Authenticating.component.js.map +0 -1
  66. package/dist/core/default-component/Callback.component.js +0 -54
  67. package/dist/core/default-component/Callback.component.js.map +0 -1
  68. package/dist/core/default-component/Loading.component.js +0 -6
  69. package/dist/core/default-component/Loading.component.js.map +0 -1
  70. package/dist/core/default-component/ServiceWorkerNotSupported.component.js +0 -6
  71. package/dist/core/default-component/ServiceWorkerNotSupported.component.js.map +0 -1
  72. package/dist/core/default-component/SessionLost.component.js +0 -8
  73. package/dist/core/default-component/SessionLost.component.js.map +0 -1
  74. package/dist/core/default-component/SilentCallback.component.js +0 -27
  75. package/dist/core/default-component/SilentCallback.component.js.map +0 -1
  76. package/dist/core/default-component/SilentLogin.component.js +0 -29
  77. package/dist/core/default-component/SilentLogin.component.js.map +0 -1
  78. package/dist/core/default-component/index.js +0 -20
  79. package/dist/core/default-component/index.js.map +0 -1
  80. package/dist/core/routes/OidcRoutes.js +0 -64
  81. package/dist/core/routes/OidcRoutes.js.map +0 -1
  82. package/dist/core/routes/withRouter.js +0 -31
  83. package/dist/core/routes/withRouter.js.map +0 -1
  84. package/dist/index.js.map +0 -1
  85. package/dist/service_worker/OidcServiceWorker.d.ts +0 -2
  86. package/dist/service_worker/OidcServiceWorker.d.ts.map +0 -1
  87. package/dist/service_worker/OidcServiceWorker.js +0 -2
  88. package/dist/service_worker/OidcServiceWorker.js.map +0 -1
  89. package/dist/service_worker/constants.d.ts +0 -18
  90. package/dist/service_worker/constants.d.ts.map +0 -1
  91. package/dist/service_worker/types.d.ts +0 -87
  92. package/dist/service_worker/types.d.ts.map +0 -1
  93. package/dist/service_worker/utils/codeVerifier.d.ts +0 -2
  94. package/dist/service_worker/utils/codeVerifier.d.ts.map +0 -1
  95. package/dist/service_worker/utils/domains.d.ts +0 -7
  96. package/dist/service_worker/utils/domains.d.ts.map +0 -1
  97. package/dist/service_worker/utils/index.d.ts +0 -6
  98. package/dist/service_worker/utils/index.d.ts.map +0 -1
  99. package/dist/service_worker/utils/serializeHeaders.d.ts +0 -3
  100. package/dist/service_worker/utils/serializeHeaders.d.ts.map +0 -1
  101. package/dist/service_worker/utils/sleep.d.ts +0 -3
  102. package/dist/service_worker/utils/sleep.d.ts.map +0 -1
  103. package/dist/service_worker/utils/strings.d.ts +0 -8
  104. package/dist/service_worker/utils/strings.d.ts.map +0 -1
  105. package/dist/service_worker/utils/tokens.d.ts +0 -22
  106. package/dist/service_worker/utils/tokens.d.ts.map +0 -1
  107. package/dist/tsconfig.tsbuildinfo +0 -1
  108. package/dist/vanilla/cache.d.ts +0 -3
  109. package/dist/vanilla/cache.d.ts.map +0 -1
  110. package/dist/vanilla/cache.js +0 -30
  111. package/dist/vanilla/cache.js.map +0 -1
  112. package/dist/vanilla/checkSession.d.ts +0 -4
  113. package/dist/vanilla/checkSession.d.ts.map +0 -1
  114. package/dist/vanilla/checkSession.js +0 -73
  115. package/dist/vanilla/checkSession.js.map +0 -1
  116. package/dist/vanilla/checkSessionIFrame.d.ts +0 -17
  117. package/dist/vanilla/checkSessionIFrame.d.ts.map +0 -1
  118. package/dist/vanilla/checkSessionIFrame.js +0 -73
  119. package/dist/vanilla/checkSessionIFrame.js.map +0 -1
  120. package/dist/vanilla/crypto.d.ts +0 -4
  121. package/dist/vanilla/crypto.d.ts.map +0 -1
  122. package/dist/vanilla/crypto.js +0 -85
  123. package/dist/vanilla/crypto.js.map +0 -1
  124. package/dist/vanilla/events.d.ts +0 -29
  125. package/dist/vanilla/events.d.ts.map +0 -1
  126. package/dist/vanilla/events.js +0 -32
  127. package/dist/vanilla/events.js.map +0 -1
  128. package/dist/vanilla/index.d.ts +0 -3
  129. package/dist/vanilla/index.d.ts.map +0 -1
  130. package/dist/vanilla/index.js +0 -6
  131. package/dist/vanilla/index.js.map +0 -1
  132. package/dist/vanilla/initSession.d.ts +0 -22
  133. package/dist/vanilla/initSession.d.ts.map +0 -1
  134. package/dist/vanilla/initSession.js +0 -90
  135. package/dist/vanilla/initSession.js.map +0 -1
  136. package/dist/vanilla/initWorker.d.ts +0 -30
  137. package/dist/vanilla/initWorker.d.ts.map +0 -1
  138. package/dist/vanilla/initWorker.js +0 -317
  139. package/dist/vanilla/initWorker.js.map +0 -1
  140. package/dist/vanilla/login.d.ts +0 -8
  141. package/dist/vanilla/login.d.ts.map +0 -1
  142. package/dist/vanilla/login.js +0 -175
  143. package/dist/vanilla/login.js.map +0 -1
  144. package/dist/vanilla/logout.d.ts +0 -8
  145. package/dist/vanilla/logout.d.ts.map +0 -1
  146. package/dist/vanilla/logout.js +0 -118
  147. package/dist/vanilla/logout.js.map +0 -1
  148. package/dist/vanilla/oidc.d.ts +0 -101
  149. package/dist/vanilla/oidc.d.ts.map +0 -1
  150. package/dist/vanilla/oidc.js +0 -612
  151. package/dist/vanilla/oidc.js.map +0 -1
  152. package/dist/vanilla/parseTokens.d.ts +0 -37
  153. package/dist/vanilla/parseTokens.d.ts.map +0 -1
  154. package/dist/vanilla/parseTokens.js +0 -167
  155. package/dist/vanilla/parseTokens.js.map +0 -1
  156. package/dist/vanilla/renewTokens.d.ts +0 -4
  157. package/dist/vanilla/renewTokens.d.ts.map +0 -1
  158. package/dist/vanilla/renewTokens.js +0 -51
  159. package/dist/vanilla/renewTokens.js.map +0 -1
  160. package/dist/vanilla/requests.d.ts +0 -33
  161. package/dist/vanilla/requests.d.ts.map +0 -1
  162. package/dist/vanilla/requests.js +0 -174
  163. package/dist/vanilla/requests.js.map +0 -1
  164. package/dist/vanilla/route-utils.d.ts +0 -13
  165. package/dist/vanilla/route-utils.d.ts.map +0 -1
  166. package/dist/vanilla/route-utils.js +0 -71
  167. package/dist/vanilla/route-utils.js.map +0 -1
  168. package/dist/vanilla/silentLogin.d.ts +0 -10
  169. package/dist/vanilla/silentLogin.d.ts.map +0 -1
  170. package/dist/vanilla/silentLogin.js +0 -144
  171. package/dist/vanilla/silentLogin.js.map +0 -1
  172. package/dist/vanilla/timer.d.ts +0 -8
  173. package/dist/vanilla/timer.d.ts.map +0 -1
  174. package/dist/vanilla/timer.js +0 -143
  175. package/dist/vanilla/timer.js.map +0 -1
  176. package/dist/vanilla/types.d.ts +0 -38
  177. package/dist/vanilla/types.d.ts.map +0 -1
  178. package/dist/vanilla/types.js +0 -3
  179. package/dist/vanilla/types.js.map +0 -1
  180. package/dist/vanilla/user.d.ts +0 -2
  181. package/dist/vanilla/user.d.ts.map +0 -1
  182. package/dist/vanilla/user.js +0 -48
  183. package/dist/vanilla/user.js.map +0 -1
  184. package/dist/vanilla/vanillaOidc.d.ts +0 -85
  185. package/dist/vanilla/vanillaOidc.d.ts.map +0 -1
  186. package/dist/vanilla/vanillaOidc.js +0 -71
  187. package/dist/vanilla/vanillaOidc.js.map +0 -1
  188. package/service_worker/.eslintrc.cjs +0 -18
  189. package/service_worker/OidcServiceWorker.ts +0 -424
  190. package/service_worker/constants.ts +0 -32
  191. package/service_worker/dist/OidcServiceWorker.d.ts +0 -2
  192. package/service_worker/dist/OidcServiceWorker.d.ts.map +0 -1
  193. package/service_worker/dist/OidcServiceWorker.js +0 -2
  194. package/service_worker/dist/OidcServiceWorker.js.map +0 -1
  195. package/service_worker/dist/constants.d.ts +0 -18
  196. package/service_worker/dist/constants.d.ts.map +0 -1
  197. package/service_worker/dist/types.d.ts +0 -87
  198. package/service_worker/dist/types.d.ts.map +0 -1
  199. package/service_worker/dist/utils/codeVerifier.d.ts +0 -2
  200. package/service_worker/dist/utils/codeVerifier.d.ts.map +0 -1
  201. package/service_worker/dist/utils/domains.d.ts +0 -7
  202. package/service_worker/dist/utils/domains.d.ts.map +0 -1
  203. package/service_worker/dist/utils/index.d.ts +0 -6
  204. package/service_worker/dist/utils/index.d.ts.map +0 -1
  205. package/service_worker/dist/utils/serializeHeaders.d.ts +0 -3
  206. package/service_worker/dist/utils/serializeHeaders.d.ts.map +0 -1
  207. package/service_worker/dist/utils/sleep.d.ts +0 -3
  208. package/service_worker/dist/utils/sleep.d.ts.map +0 -1
  209. package/service_worker/dist/utils/strings.d.ts +0 -8
  210. package/service_worker/dist/utils/strings.d.ts.map +0 -1
  211. package/service_worker/dist/utils/tokens.d.ts +0 -22
  212. package/service_worker/dist/utils/tokens.d.ts.map +0 -1
  213. package/service_worker/tsconfig.json +0 -26
  214. package/service_worker/types.ts +0 -103
  215. package/service_worker/utils/__tests__/codeVerifier.spec.ts +0 -14
  216. package/service_worker/utils/__tests__/domains.spec.ts +0 -90
  217. package/service_worker/utils/__tests__/serializeHeaders.spec.ts +0 -11
  218. package/service_worker/utils/__tests__/strings.spec.ts +0 -9
  219. package/service_worker/utils/__tests__/testHelper.ts +0 -352
  220. package/service_worker/utils/__tests__/tokens.spec.ts +0 -92
  221. package/service_worker/utils/codeVerifier.ts +0 -6
  222. package/service_worker/utils/domains.ts +0 -105
  223. package/service_worker/utils/index.ts +0 -5
  224. package/service_worker/utils/serializeHeaders.ts +0 -12
  225. package/service_worker/utils/sleep.ts +0 -2
  226. package/service_worker/utils/strings.ts +0 -9
  227. package/service_worker/utils/tokens.ts +0 -206
  228. package/src/oidc/vanilla/cache.ts +0 -27
  229. package/src/oidc/vanilla/checkSession.ts +0 -60
  230. package/src/oidc/vanilla/checkSessionIFrame.ts +0 -83
  231. package/src/oidc/vanilla/crypto.ts +0 -61
  232. package/src/oidc/vanilla/events.ts +0 -29
  233. package/src/oidc/vanilla/index.ts +0 -2
  234. package/src/oidc/vanilla/iniWorker.spec.ts +0 -21
  235. package/src/oidc/vanilla/initSession.ts +0 -90
  236. package/src/oidc/vanilla/initWorker.ts +0 -321
  237. package/src/oidc/vanilla/login.ts +0 -174
  238. package/src/oidc/vanilla/logout.spec.ts +0 -66
  239. package/src/oidc/vanilla/logout.spec.tsx +0 -64
  240. package/src/oidc/vanilla/logout.ts +0 -101
  241. package/src/oidc/vanilla/oidc.ts +0 -614
  242. package/src/oidc/vanilla/parseTokens.spec.ts +0 -49
  243. package/src/oidc/vanilla/parseTokens.ts +0 -194
  244. package/src/oidc/vanilla/renewTokens.ts +0 -37
  245. package/src/oidc/vanilla/requests.spec.ts +0 -9
  246. package/src/oidc/vanilla/requests.ts +0 -169
  247. package/src/oidc/vanilla/route-utils.spec.ts +0 -23
  248. package/src/oidc/vanilla/route-utils.ts +0 -79
  249. package/src/oidc/vanilla/silentLogin.ts +0 -144
  250. package/src/oidc/vanilla/timer.ts +0 -163
  251. package/src/oidc/vanilla/types.ts +0 -42
  252. package/src/oidc/vanilla/user.ts +0 -40
  253. package/src/oidc/vanilla/vanillaOidc.ts +0 -109
  254. package/src/override/AuthenticateError.component.tsx +0 -15
  255. package/src/override/Authenticating.component.tsx +0 -15
  256. package/src/override/Callback.component.tsx +0 -14
  257. package/src/override/Loading.component.tsx +0 -11
  258. package/src/override/ServiceWorkerNotSupported.component.tsx +0 -15
  259. package/src/override/SessionLost.component.tsx +0 -22
  260. package/src/override/style.ts +0 -12
  261. /package/src/{oidc/core → core}/default-component/index.ts +0 -0
  262. /package/src/{oidc/core → core}/routes/__snapshots__/OidcRoutes.spec.tsx.snap +0 -0
  263. /package/src/{oidc/core → core}/routes/index.ts +0 -0
  264. /package/src/{oidc/core → core}/routes/withRouter.tsx +0 -0
@@ -1,71 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.VanillaOidc = void 0;
13
- const oidc_js_1 = require("./oidc.js");
14
- const parseTokens_js_1 = require("./parseTokens.js");
15
- class VanillaOidc {
16
- constructor(oidc) {
17
- this._oidc = oidc;
18
- }
19
- subscribeEvents(func) {
20
- return this._oidc.subscribeEvents(func);
21
- }
22
- removeEventSubscription(id) {
23
- this._oidc.removeEventSubscription(id);
24
- }
25
- publishEvent(eventName, data) {
26
- this._oidc.publishEvent(eventName, data);
27
- }
28
- static get(name = 'default') {
29
- return new VanillaOidc(oidc_js_1.Oidc.get(name));
30
- }
31
- tryKeepExistingSessionAsync() {
32
- return this._oidc.tryKeepExistingSessionAsync();
33
- }
34
- loginAsync(callbackPath = undefined, extras = null, isSilentSignin = false, scope = undefined, silentLoginOnly = false) {
35
- return this._oidc.loginAsync(callbackPath, extras, isSilentSignin, scope, silentLoginOnly);
36
- }
37
- logoutAsync(callbackPathOrUrl = undefined, extras = null) {
38
- return this._oidc.logoutAsync(callbackPathOrUrl, extras);
39
- }
40
- silentLoginCallbackAsync() {
41
- return this._oidc.silentLoginCallbackAsync();
42
- }
43
- renewTokensAsync(extras = null) {
44
- return this._oidc.renewTokensAsync(extras);
45
- }
46
- loginCallbackAsync() {
47
- return this._oidc.loginCallbackWithAutoTokensRenewAsync();
48
- }
49
- get tokens() {
50
- return this._oidc.tokens;
51
- }
52
- get configuration() {
53
- return this._oidc.configuration;
54
- }
55
- getValidTokenAsync(waitMs = 200, numberWait = 50) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- return (0, parseTokens_js_1.getValidTokenAsync)(this._oidc, waitMs, numberWait);
58
- });
59
- }
60
- userInfoAsync(noCache = false) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- return this._oidc.userInfoAsync(noCache);
63
- });
64
- }
65
- }
66
- exports.VanillaOidc = VanillaOidc;
67
- VanillaOidc.getOrCreate = (getFetch) => (configuration, name = 'default') => {
68
- return new VanillaOidc(oidc_js_1.Oidc.getOrCreate(getFetch)(configuration, name));
69
- };
70
- VanillaOidc.eventNames = oidc_js_1.Oidc.eventNames;
71
- //# sourceMappingURL=vanillaOidc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vanillaOidc.js","sourceRoot":"","sources":["../../src/oidc/vanilla/vanillaOidc.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,uCAAgD;AAChD,qDAA0E;AAO1E,MAAa,WAAW;IAEpB,YAAY,IAAU;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,eAAe,CAAC,IAAoB;QAChC,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,uBAAuB,CAAC,EAAS;QAC7B,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,YAAY,CAAC,SAAgB,EAAE,IAAQ;QACnC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAMD,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,SAAS;QACvB,OAAO,IAAI,WAAW,CAAC,cAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,CAAC;IAGD,2BAA2B;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,2BAA2B,EAAE,CAAC;IACpD,CAAC;IAED,UAAU,CAAC,eAAsB,SAAS,EAAE,SAAmB,IAAI,EAAE,cAAc,GAAG,KAAK,EAAE,QAAe,SAAS,EAAE,eAAe,GAAG,KAAK;QAC1I,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;IAC/F,CAAC;IAED,WAAW,CAAC,oBAA+C,SAAS,EAAE,SAAoB,IAAI;QAC1F,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAC7D,CAAC;IAED,wBAAwB;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;IACjD,CAAC;IAED,gBAAgB,CAAC,SAAmB,IAAI;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED,kBAAkB;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,qCAAqC,EAAE,CAAC;IAC9D,CAAC;IAED,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,IAAI,aAAa;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;IACpC,CAAC;IAEK,kBAAkB,CAAC,MAAM,GAAG,GAAG,EAAE,UAAU,GAAG,EAAE;;YAClD,OAAO,IAAA,mCAAkB,EAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;QAC9D,CAAC;KAAA;IAEK,aAAa,CAAwC,OAAO,GAAG,KAAK;;YACtE,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;KAAA;;AAjEL,kCAkEC;AAhDU,uBAAW,GAAG,CAAC,QAAsB,EAAE,EAAE,CAAC,CAAC,aAA+B,EAAE,IAAI,GAAG,SAAS,EAAe,EAAE;IAChH,OAAO,IAAI,WAAW,CAAC,cAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC;AAC5E,CAAC,CAAC;AAMK,sBAAU,GAAG,cAAI,CAAC,UAAU,CAAC"}
@@ -1,18 +0,0 @@
1
- module.exports = {
2
- extends: [__dirname + '/config/defaultEslintConfig'],
3
- parserOptions: {
4
- project: '../tsconfig.eslint.json',
5
- tsconfigRootDir: __dirname,
6
- },
7
- rules: {
8
- '@typescript-eslint/naming-convention': [
9
- 'error',
10
- {
11
- selector: 'variable',
12
- types: ['boolean'],
13
- format: ['PascalCase'],
14
- prefix: ['is', 'with', 'should', 'has', 'can', 'did', 'will'],
15
- },
16
- ],
17
- },
18
- };
@@ -1,424 +0,0 @@
1
- import { acceptAnyDomainToken, TOKEN, scriptFilename } from './constants';
2
- import {
3
- TrustedDomains,
4
- Database,
5
- OidcConfig,
6
- OidcConfiguration,
7
- MessageEventData,
8
- // TrustedDomainsShowAccessToken,
9
- } from './types';
10
- import {
11
- checkDomain,
12
- getCurrentDatabaseDomain,
13
- hideTokens,
14
- isTokensValid,
15
- serializeHeaders,
16
- sleep,
17
- getDomains,
18
- } from './utils';
19
- import {replaceCodeVerifier} from "./utils/codeVerifier";
20
-
21
- const _self = self as ServiceWorkerGlobalScope & typeof globalThis;
22
-
23
- declare let trustedDomains: TrustedDomains;
24
-
25
- _self.importScripts(scriptFilename);
26
-
27
- const id = Math.round(new Date().getTime() / 1000).toString();
28
-
29
- const keepAliveJsonFilename = 'OidcKeepAliveServiceWorker.json';
30
- const handleInstall = (event: ExtendableEvent) => {
31
- console.log('[OidcServiceWorker] service worker installed ' + id);
32
- event.waitUntil(_self.skipWaiting());
33
- };
34
-
35
- const handleActivate = (event: ExtendableEvent) => {
36
- console.log('[OidcServiceWorker] service worker activated ' + id);
37
- event.waitUntil(_self.clients.claim());
38
- };
39
-
40
- let currentLoginCallbackConfigurationName: string | null = null;
41
- const database: Database = {
42
- default: {
43
- configurationName: 'default',
44
- tokens: null,
45
- status: null,
46
- state: null,
47
- codeVerifier: null,
48
- nonce: null,
49
- oidcServerConfiguration: null,
50
- hideAccessToken: true,
51
- },
52
- };
53
-
54
- const getCurrentDatabasesTokenEndpoint = (database: Database, url: string) => {
55
- const databases: OidcConfig[] = [];
56
- for (const [, value] of Object.entries<OidcConfig>(database)) {
57
- if (
58
- value.oidcServerConfiguration != null &&
59
- url.startsWith(value.oidcServerConfiguration.tokenEndpoint)
60
- ) {
61
- databases.push(value);
62
- } else if (
63
- value.oidcServerConfiguration != null &&
64
- value.oidcServerConfiguration.revocationEndpoint &&
65
- url.startsWith(value.oidcServerConfiguration.revocationEndpoint)
66
- ) {
67
- databases.push(value);
68
- }
69
- }
70
- return databases;
71
- };
72
-
73
- const keepAliveAsync = async (event: FetchEvent) => {
74
- const originalRequest = event.request;
75
- const isFromVanilla = originalRequest.headers.has('oidc-vanilla');
76
- const init = { status: 200, statusText: 'oidc-service-worker' };
77
- const response = new Response('{}', init);
78
- if (!isFromVanilla) {
79
- const originalRequestUrl = new URL(originalRequest.url);
80
- const minSleepSeconds = Number(originalRequestUrl.searchParams.get('minSleepSeconds')) || 240;
81
- for (let i = 0; i < minSleepSeconds; i++) {
82
- await sleep(1000 + Math.floor(Math.random() * 1000));
83
- const cache = await caches.open('oidc_dummy_cache');
84
- await cache.put(event.request, response.clone());
85
- }
86
- }
87
- return response;
88
- };
89
-
90
- const handleFetch = async (event: FetchEvent) => {
91
- const originalRequest = event.request;
92
- const url = originalRequest.url;
93
- if (originalRequest.url.includes(keepAliveJsonFilename)) {
94
- event.respondWith(keepAliveAsync(event));
95
- return;
96
- }
97
-
98
- const currentDatabaseForRequestAccessToken = getCurrentDatabaseDomain(
99
- database,
100
- originalRequest.url,
101
- trustedDomains
102
- );
103
- if (
104
- currentDatabaseForRequestAccessToken &&
105
- currentDatabaseForRequestAccessToken.tokens &&
106
- currentDatabaseForRequestAccessToken.tokens.access_token
107
- ) {
108
- while (
109
- currentDatabaseForRequestAccessToken.tokens &&
110
- !isTokensValid(currentDatabaseForRequestAccessToken.tokens)
111
- ) {
112
- await sleep(200);
113
- }
114
- const newRequest =
115
- originalRequest.mode == 'navigate'
116
- ? new Request(originalRequest, {
117
- headers: {
118
- ...serializeHeaders(originalRequest.headers),
119
- authorization:
120
- 'Bearer ' +
121
- currentDatabaseForRequestAccessToken.tokens.access_token,
122
- },
123
- })
124
- : new Request(originalRequest, {
125
- headers: {
126
- ...serializeHeaders(originalRequest.headers),
127
- authorization:
128
- 'Bearer ' +
129
- currentDatabaseForRequestAccessToken.tokens.access_token,
130
- },
131
- mode: (
132
- currentDatabaseForRequestAccessToken.oidcConfiguration as OidcConfiguration
133
- ).service_worker_convert_all_requests_to_cors
134
- ? 'cors'
135
- : originalRequest.mode,
136
- });
137
-
138
- //@ts-ignore -- TODO: review, waitUntil takes a promise, this returns a void
139
- event.waitUntil(event.respondWith(fetch(newRequest)));
140
-
141
- return;
142
- }
143
-
144
- if (event.request.method !== 'POST') {
145
- return;
146
- }
147
-
148
- let currentDatabase: OidcConfig | null = null;
149
- const currentDatabases = getCurrentDatabasesTokenEndpoint(
150
- database,
151
- originalRequest.url
152
- );
153
- const numberDatabase = currentDatabases.length;
154
- if (numberDatabase > 0) {
155
- const maPromesse = new Promise<Response>((resolve, reject) => {
156
- const clonedRequest = originalRequest.clone();
157
- const response = clonedRequest.text().then((actualBody) => {
158
- if (
159
- actualBody.includes(TOKEN.REFRESH_TOKEN) ||
160
- actualBody.includes(TOKEN.ACCESS_TOKEN)
161
- ) {
162
- let newBody = actualBody;
163
- for (let i = 0; i < numberDatabase; i++) {
164
- const currentDb = currentDatabases[i];
165
-
166
- if (currentDb && currentDb.tokens != null) {
167
- const keyRefreshToken =
168
- TOKEN.REFRESH_TOKEN + '_' + currentDb.configurationName;
169
- if (actualBody.includes(keyRefreshToken)) {
170
- newBody = newBody.replace(
171
- keyRefreshToken,
172
- encodeURIComponent(currentDb.tokens.refresh_token as string)
173
- );
174
- currentDatabase = currentDb;
175
- break;
176
- }
177
- const keyAccessToken =
178
- TOKEN.ACCESS_TOKEN + '_' + currentDb.configurationName;
179
- if (actualBody.includes(keyAccessToken)) {
180
- newBody = newBody.replace(
181
- keyAccessToken,
182
- encodeURIComponent(currentDb.tokens.access_token)
183
- );
184
- currentDatabase = currentDb;
185
- break;
186
- }
187
- }
188
- }
189
- const fetchPromise = fetch(originalRequest, {
190
- body: newBody,
191
- method: clonedRequest.method,
192
- headers: {
193
- ...serializeHeaders(originalRequest.headers),
194
- },
195
- mode: clonedRequest.mode,
196
- cache: clonedRequest.cache,
197
- redirect: clonedRequest.redirect,
198
- referrer: clonedRequest.referrer,
199
- credentials: clonedRequest.credentials,
200
- integrity: clonedRequest.integrity,
201
- });
202
-
203
- if (
204
- currentDatabase &&
205
- currentDatabase.oidcServerConfiguration != null &&
206
- currentDatabase.oidcServerConfiguration.revocationEndpoint &&
207
- url.startsWith(
208
- currentDatabase.oidcServerConfiguration.revocationEndpoint
209
- )
210
- ) {
211
- return fetchPromise.then(async (response) => {
212
- const text = await response.text();
213
- return new Response(text, response);
214
- });
215
- }
216
- return fetchPromise.then(hideTokens(currentDatabase as OidcConfig)); //todo type assertion to OidcConfig but could be null, NEEDS REVIEW
217
- } else if (
218
- actualBody.includes('code_verifier=') &&
219
- currentLoginCallbackConfigurationName
220
- ) {
221
- currentDatabase = database[currentLoginCallbackConfigurationName];
222
- currentLoginCallbackConfigurationName = null;
223
- let newBody = actualBody;
224
- if (currentDatabase && currentDatabase.codeVerifier != null) {
225
- newBody = replaceCodeVerifier(newBody, currentDatabase.codeVerifier);
226
- }
227
-
228
- return fetch(originalRequest, {
229
- body: newBody,
230
- method: clonedRequest.method,
231
- headers: {
232
- ...serializeHeaders(originalRequest.headers),
233
- },
234
- mode: clonedRequest.mode,
235
- cache: clonedRequest.cache,
236
- redirect: clonedRequest.redirect,
237
- referrer: clonedRequest.referrer,
238
- credentials: clonedRequest.credentials,
239
- integrity: clonedRequest.integrity,
240
- }).then(hideTokens(currentDatabase));
241
- }
242
- return undefined;
243
- });
244
- response
245
- .then((r) => {
246
- if (r !== undefined) {
247
- resolve(r);
248
- } else {
249
- console.log('success undefined');
250
- reject(new Error('Response is undefined inside a success'));
251
- }
252
- })
253
- .catch((err) => {
254
- if (err !== undefined) {
255
- reject(err);
256
- } else {
257
- console.log('error undefined');
258
- reject(new Error('Response is undefined inside a error'));
259
- }
260
- });
261
- });
262
-
263
- //@ts-ignore -- TODO: review, waitUntil takes a promise, this returns a void
264
- event.waitUntil(event.respondWith(maPromesse));
265
- }
266
- };
267
-
268
- type TrustedDomainsShowAccessToken = {
269
- [key: string]: boolean
270
- }
271
-
272
- const trustedDomainsShowAccessToken: TrustedDomainsShowAccessToken = {};
273
-
274
- const handleMessage = (event: ExtendableMessageEvent) => {
275
- const port = event.ports[0];
276
- const data = event.data as MessageEventData;
277
- const configurationName = data.configurationName;
278
- let currentDatabase = database[configurationName];
279
- if(trustedDomains== null){
280
- trustedDomains = {};
281
- }
282
- if (!currentDatabase) {
283
-
284
- if (trustedDomainsShowAccessToken[configurationName] === undefined) {
285
- let trustedDomain = trustedDomains[configurationName];
286
- trustedDomainsShowAccessToken[configurationName] = Array.isArray(trustedDomain) ? false : trustedDomain.showAccessToken;
287
- }
288
- database[configurationName] = {
289
- tokens: null,
290
- state: null,
291
- codeVerifier: null,
292
- oidcServerConfiguration: null,
293
- oidcConfiguration: undefined,
294
- nonce: null,
295
- status: null,
296
- configurationName,
297
- hideAccessToken: !trustedDomainsShowAccessToken[configurationName],
298
- };
299
- currentDatabase = database[configurationName];
300
-
301
- if (!trustedDomains[configurationName]) {
302
- trustedDomains[configurationName] = [];
303
- }
304
- }
305
-
306
- switch (data.type) {
307
- case 'clear':
308
- currentDatabase.tokens = null;
309
- currentDatabase.state = null;
310
- currentDatabase.codeVerifier = null;
311
- currentDatabase.status = data.data.status;
312
- port.postMessage({ configurationName });
313
- return;
314
- case 'init': {
315
- const oidcServerConfiguration = data.data.oidcServerConfiguration;
316
- let trustedDomain = trustedDomains[configurationName];
317
- const domains = getDomains(trustedDomain, 'oidc');
318
- if (!domains.find((f) => f === acceptAnyDomainToken)) {
319
- [
320
- oidcServerConfiguration.tokenEndpoint,
321
- oidcServerConfiguration.revocationEndpoint,
322
- oidcServerConfiguration.userInfoEndpoint,
323
- oidcServerConfiguration.issuer,
324
- ].forEach((url) => {
325
- checkDomain(domains, url);
326
- });
327
- }
328
- currentDatabase.oidcServerConfiguration = oidcServerConfiguration;
329
- currentDatabase.oidcConfiguration = data.data.oidcConfiguration;
330
- const where = data.data.where;
331
- if (
332
- where === 'loginCallbackAsync' ||
333
- where === 'tryKeepExistingSessionAsync'
334
- ) {
335
- currentLoginCallbackConfigurationName = configurationName;
336
- } else {
337
- currentLoginCallbackConfigurationName = null;
338
- }
339
-
340
- if (!currentDatabase.tokens) {
341
- port.postMessage({
342
- tokens: null,
343
- status: currentDatabase.status,
344
- configurationName,
345
- });
346
- } else {
347
- const tokens = {
348
- ...currentDatabase.tokens,
349
- };
350
- if(currentDatabase.hideAccessToken) {
351
- tokens.access_token = TOKEN.ACCESS_TOKEN + '_' + configurationName;
352
- }
353
- if (tokens.refresh_token) {
354
- tokens.refresh_token = TOKEN.REFRESH_TOKEN + '_' + configurationName;
355
- }
356
- if (
357
- tokens.idTokenPayload &&
358
- tokens.idTokenPayload.nonce &&
359
- currentDatabase.nonce != null
360
- ) {
361
- tokens.idTokenPayload.nonce =
362
- TOKEN.NONCE_TOKEN + '_' + configurationName;
363
- }
364
- port.postMessage({
365
- tokens,
366
- status: currentDatabase.status,
367
- configurationName,
368
- });
369
- }
370
- return;
371
- }
372
- case 'setState':
373
- currentDatabase.state = data.data.state;
374
- port.postMessage({ configurationName });
375
- return;
376
- case 'getState': {
377
- const state = currentDatabase.state;
378
- port.postMessage({ configurationName, state });
379
- return;
380
- }
381
- case 'setCodeVerifier':
382
- currentDatabase.codeVerifier = data.data.codeVerifier;
383
- port.postMessage({ configurationName });
384
- return;
385
- case 'getCodeVerifier': {
386
- port.postMessage({
387
- configurationName,
388
- codeVerifier: currentDatabase.codeVerifier != null ? TOKEN.CODE_VERIFIER + '_' + configurationName : null,
389
- });
390
- return;
391
- }
392
- case 'setSessionState':
393
- currentDatabase.sessionState = data.data.sessionState;
394
- port.postMessage({ configurationName });
395
- return;
396
- case 'getSessionState': {
397
- const sessionState = currentDatabase.sessionState;
398
- port.postMessage({ configurationName, sessionState });
399
- return;
400
- }
401
- case 'setNonce': {
402
- let nonce = data.data.nonce;
403
- if (nonce) {
404
- currentDatabase.nonce = nonce;
405
- }
406
- port.postMessage({configurationName});
407
- return;
408
- }
409
- case 'getNonce': {
410
- const keyNonce = TOKEN.NONCE_TOKEN + '_' + configurationName;
411
- const nonce = currentDatabase.nonce ? keyNonce : null;
412
- port.postMessage({configurationName, nonce});
413
- return;
414
- }
415
- default:
416
- currentDatabase.items = { ...data.data };
417
- port.postMessage({ configurationName });
418
- }
419
- };
420
-
421
- _self.addEventListener('install', handleInstall);
422
- _self.addEventListener('activate', handleActivate);
423
- _self.addEventListener('fetch', handleFetch);
424
- _self.addEventListener('message', handleMessage);
@@ -1,32 +0,0 @@
1
- const scriptFilename = 'OidcTrustedDomains.js'; /* global trustedDomains */
2
- const acceptAnyDomainToken = '*';
3
-
4
- type TokenType = {
5
- readonly REFRESH_TOKEN: string;
6
- readonly ACCESS_TOKEN: string;
7
- readonly NONCE_TOKEN: string;
8
- readonly CODE_VERIFIER: string;
9
- };
10
-
11
- const TOKEN: TokenType = {
12
- REFRESH_TOKEN: 'REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER',
13
- ACCESS_TOKEN: 'ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER',
14
- NONCE_TOKEN: 'NONCE_SECURED_BY_OIDC_SERVICE_WORKER',
15
- CODE_VERIFIER: 'CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER',
16
- };
17
-
18
- type TokenRenewModeType = {
19
- readonly access_token_or_id_token_invalid: string;
20
- readonly access_token_invalid: string;
21
- readonly id_token_invalid: string;
22
- };
23
-
24
- const TokenRenewMode: TokenRenewModeType = {
25
- access_token_or_id_token_invalid: 'access_token_or_id_token_invalid',
26
- access_token_invalid: 'access_token_invalid',
27
- id_token_invalid: 'id_token_invalid',
28
- };
29
-
30
- const openidWellknownUrlEndWith = '/.well-known/openid-configuration';
31
-
32
- export { scriptFilename, acceptAnyDomainToken, TOKEN, TokenRenewMode, openidWellknownUrlEndWith };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=OidcServiceWorker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OidcServiceWorker.d.ts","sourceRoot":"","sources":["../OidcServiceWorker.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- "use strict";const y="OidcTrustedDomains.js",A="*",_={REFRESH_TOKEN:"REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",ACCESS_TOKEN:"ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",NONCE_TOKEN:"NONCE_SECURED_BY_OIDC_SERVICE_WORKER",CODE_VERIFIER:"CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER"},w={access_token_or_id_token_invalid:"access_token_or_id_token_invalid",access_token_invalid:"access_token_invalid",id_token_invalid:"id_token_invalid"},I="/.well-known/openid-configuration";function K(n,e){if(!e)return;if(!n.find(o=>{var s;let t;return typeof o=="string"?t=new RegExp(`^${o}`):t=o,(s=t.test)==null?void 0:s.call(t,e)}))throw new Error("Domain "+e+" is not trusted, please add domain in "+y)}const D=(n,e)=>Array.isArray(n)?n:n[`${e}Domains`]??n.domains??[],M=(n,e,i)=>{var o;if(e.endsWith(I))return null;for(const[t,s]of Object.entries(n)){const d=s.oidcServerConfiguration;if(!d||d.tokenEndpoint&&e===d.tokenEndpoint||d.revocationEndpoint&&e===d.revocationEndpoint)continue;const l=i==null?[]:i[t],f=D(l,"accessToken"),r=d.userInfoEndpoint?[d.userInfoEndpoint,...f]:[...f];let a=!1;if(r.find(h=>h===A))a=!0;else for(let h=0;h<r.length;h++){let c=r[h];if(typeof c=="string"&&(c=new RegExp(`^${c}`)),(o=c.test)!=null&&o.call(c,e)){a=!0;break}}if(a)return s.tokens?s:null}return null};function U(n,e){return n.split(e).length-1}function P(n){return JSON.parse(W(n.split(".")[1].replace("-","+").replace("_","/")))}function W(n){return decodeURIComponent(Array.prototype.map.call(atob(n),e=>"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)).join(""))}function F(n,e){const i=new Date().getTime()/1e3;return Math.round(e-n-i)}function b(n){return n?F(0,n.expiresAt)>0:!1}const O=n=>{try{return n&&U(n,".")===2?P(n):null}catch(e){console.warn(e)}return null},q=(n,e,i)=>{if(n.idTokenPayload){const o=n.idTokenPayload;if(i.issuer!==o.iss)return{isValid:!1,reason:"Issuer does not match"};const t=new Date().getTime()/1e3;if(o.exp&&o.exp<t)return{isValid:!1,reason:"Token expired"};const s=60*60*24*7;if(o.iat&&o.iat+s<t)return{isValid:!1,reason:"Token is used from too long time"};if(e&&o.nonce&&o.nonce!==e)return{isValid:!1,reason:"Nonce does not match"}}return{isValid:!0,reason:""}};function L(n,e,i){if(!n.issued_at){const u=new Date().getTime()/1e3;n.issued_at=u}const o=O(n.access_token),t={...n,accessTokenPayload:o};e.hideAccessToken&&(t.access_token=_.ACCESS_TOKEN+"_"+i),n.accessTokenPayload=o;let s=null;if(n.id_token){if(s=O(n.id_token),n.idTokenPayload={...s},s.nonce&&e.nonce!=null){const u=_.NONCE_TOKEN+"_"+e.configurationName;s.nonce=u}t.idTokenPayload=s}n.refresh_token&&(t.refresh_token=_.REFRESH_TOKEN+"_"+i);const d=s&&s.exp?s.exp:Number.MAX_VALUE,l=o&&o.exp?o.exp:n.issued_at+n.expires_in;let f;const r=e.oidcConfiguration.token_renew_mode;r===w.access_token_invalid?f=l:r===w.id_token_invalid?f=d:f=d<l?d:l,t.expiresAt=f,n.expiresAt=f;const a=e.nonce?e.nonce.nonce:null,{isValid:h,reason:c}=q(n,a,e.oidcServerConfiguration);if(!h)throw Error(`Tokens are not OpenID valid, reason: ${c}`);if(e.tokens!=null&&"refresh_token"in e.tokens&&!("refresh_token"in n)){const u=e.tokens.refresh_token;e.tokens={...n,refresh_token:u}}else e.tokens=n;return e.status="LOGGED_IN",t}function N(n){const e=n.configurationName;return i=>i.status!==200?i:i.json().then(o=>{const t=L(o,n,e),s=JSON.stringify(t);return new Response(s,i)})}function T(n){const e={};for(const i of n.keys())n.has(i)&&(e[i]=n.get(i));return e}const V=n=>new Promise(e=>setTimeout(e,n));function H(n,e){const i=/code_verifier=[A-Za-z0-9_-]+/i;return n.replace(i,`code_verifier=${e}`)}const p=self;p.importScripts(y);const x=Math.round(new Date().getTime()/1e3).toString(),j="OidcKeepAliveServiceWorker.json",$=n=>{console.log("[OidcServiceWorker] service worker installed "+x),n.waitUntil(p.skipWaiting())},z=n=>{console.log("[OidcServiceWorker] service worker activated "+x),n.waitUntil(p.clients.claim())};let S=null;const g={default:{configurationName:"default",tokens:null,status:null,state:null,codeVerifier:null,nonce:null,oidcServerConfiguration:null,hideAccessToken:!0}},J=(n,e)=>{const i=[];for(const[,o]of Object.entries(n))(o.oidcServerConfiguration!=null&&e.startsWith(o.oidcServerConfiguration.tokenEndpoint)||o.oidcServerConfiguration!=null&&o.oidcServerConfiguration.revocationEndpoint&&e.startsWith(o.oidcServerConfiguration.revocationEndpoint))&&i.push(o);return i},Y=async n=>{const e=n.request,i=e.headers.has("oidc-vanilla"),o={status:200,statusText:"oidc-service-worker"},t=new Response("{}",o);if(!i){const s=new URL(e.url),d=Number(s.searchParams.get("minSleepSeconds"))||240;for(let l=0;l<d;l++)await V(1e3+Math.floor(Math.random()*1e3)),await(await caches.open("oidc_dummy_cache")).put(n.request,t.clone())}return t},B=async n=>{const e=n.request,i=e.url;if(e.url.includes(j)){n.respondWith(Y(n));return}const o=M(g,e.url,trustedDomains);if(o&&o.tokens&&o.tokens.access_token){for(;o.tokens&&!b(o.tokens);)await V(200);const l=e.mode=="navigate"?new Request(e,{headers:{...T(e.headers),authorization:"Bearer "+o.tokens.access_token}}):new Request(e,{headers:{...T(e.headers),authorization:"Bearer "+o.tokens.access_token},mode:o.oidcConfiguration.service_worker_convert_all_requests_to_cors?"cors":e.mode});n.waitUntil(n.respondWith(fetch(l)));return}if(n.request.method!=="POST")return;let t=null;const s=J(g,e.url),d=s.length;if(d>0){const l=new Promise((f,r)=>{const a=e.clone();a.text().then(c=>{if(c.includes(_.REFRESH_TOKEN)||c.includes(_.ACCESS_TOKEN)){let u=c;for(let E=0;E<d;E++){const k=s[E];if(k&&k.tokens!=null){const R=_.REFRESH_TOKEN+"_"+k.configurationName;if(c.includes(R)){u=u.replace(R,encodeURIComponent(k.tokens.refresh_token)),t=k;break}const v=_.ACCESS_TOKEN+"_"+k.configurationName;if(c.includes(v)){u=u.replace(v,encodeURIComponent(k.tokens.access_token)),t=k;break}}}const C=fetch(e,{body:u,method:a.method,headers:{...T(e.headers)},mode:a.mode,cache:a.cache,redirect:a.redirect,referrer:a.referrer,credentials:a.credentials,integrity:a.integrity});return t&&t.oidcServerConfiguration!=null&&t.oidcServerConfiguration.revocationEndpoint&&i.startsWith(t.oidcServerConfiguration.revocationEndpoint)?C.then(async E=>{const k=await E.text();return new Response(k,E)}):C.then(N(t))}else if(c.includes("code_verifier=")&&S){t=g[S],S=null;let u=c;return t&&t.codeVerifier!=null&&(u=H(u,t.codeVerifier)),fetch(e,{body:u,method:a.method,headers:{...T(e.headers)},mode:a.mode,cache:a.cache,redirect:a.redirect,referrer:a.referrer,credentials:a.credentials,integrity:a.integrity}).then(N(t))}}).then(c=>{c!==void 0?f(c):(console.log("success undefined"),r(new Error("Response is undefined inside a success")))}).catch(c=>{c!==void 0?r(c):(console.log("error undefined"),r(new Error("Response is undefined inside a error")))})});n.waitUntil(n.respondWith(l))}},m={},G=n=>{const e=n.ports[0],i=n.data,o=i.configurationName;let t=g[o];if(trustedDomains==null&&(trustedDomains={}),!t){if(m[o]===void 0){let s=trustedDomains[o];m[o]=Array.isArray(s)?!1:s.showAccessToken}g[o]={tokens:null,state:null,codeVerifier:null,oidcServerConfiguration:null,oidcConfiguration:void 0,nonce:null,status:null,configurationName:o,hideAccessToken:!m[o]},t=g[o],trustedDomains[o]||(trustedDomains[o]=[])}switch(i.type){case"clear":t.tokens=null,t.state=null,t.codeVerifier=null,t.status=i.data.status,e.postMessage({configurationName:o});return;case"init":{const s=i.data.oidcServerConfiguration;let d=trustedDomains[o];const l=D(d,"oidc");l.find(r=>r===A)||[s.tokenEndpoint,s.revocationEndpoint,s.userInfoEndpoint,s.issuer].forEach(r=>{K(l,r)}),t.oidcServerConfiguration=s,t.oidcConfiguration=i.data.oidcConfiguration;const f=i.data.where;if(f==="loginCallbackAsync"||f==="tryKeepExistingSessionAsync"?S=o:S=null,!t.tokens)e.postMessage({tokens:null,status:t.status,configurationName:o});else{const r={...t.tokens};t.hideAccessToken&&(r.access_token=_.ACCESS_TOKEN+"_"+o),r.refresh_token&&(r.refresh_token=_.REFRESH_TOKEN+"_"+o),r.idTokenPayload&&r.idTokenPayload.nonce&&t.nonce!=null&&(r.idTokenPayload.nonce=_.NONCE_TOKEN+"_"+o),e.postMessage({tokens:r,status:t.status,configurationName:o})}return}case"setState":t.state=i.data.state,e.postMessage({configurationName:o});return;case"getState":{const s=t.state;e.postMessage({configurationName:o,state:s});return}case"setCodeVerifier":t.codeVerifier=i.data.codeVerifier,e.postMessage({configurationName:o});return;case"getCodeVerifier":{e.postMessage({configurationName:o,codeVerifier:t.codeVerifier!=null?_.CODE_VERIFIER+"_"+o:null});return}case"setSessionState":t.sessionState=i.data.sessionState,e.postMessage({configurationName:o});return;case"getSessionState":{const s=t.sessionState;e.postMessage({configurationName:o,sessionState:s});return}case"setNonce":{let s=i.data.nonce;s&&(t.nonce=s),e.postMessage({configurationName:o});return}case"getNonce":{const s=_.NONCE_TOKEN+"_"+o,d=t.nonce?s:null;e.postMessage({configurationName:o,nonce:d});return}default:t.items={...i.data},e.postMessage({configurationName:o})}};p.addEventListener("install",$);p.addEventListener("activate",z);p.addEventListener("fetch",B);p.addEventListener("message",G);
2
- //# sourceMappingURL=OidcServiceWorker.js.map