@axa-fr/react-oidc 5.7.0-alpha0

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 (160) hide show
  1. package/README.md +502 -0
  2. package/dist/FetchToken.d.ts +10 -0
  3. package/dist/FetchToken.d.ts.map +1 -0
  4. package/dist/FetchToken.js +107 -0
  5. package/dist/FetchToken.js.map +1 -0
  6. package/dist/OidcProvider.d.ts +25 -0
  7. package/dist/OidcProvider.d.ts.map +1 -0
  8. package/dist/OidcProvider.js +133 -0
  9. package/dist/OidcProvider.js.map +1 -0
  10. package/dist/OidcSecure.d.ts +10 -0
  11. package/dist/OidcSecure.d.ts.map +1 -0
  12. package/dist/OidcSecure.js +68 -0
  13. package/dist/OidcSecure.js.map +1 -0
  14. package/dist/OidcServiceWorker.js +272 -0
  15. package/dist/OidcTrustedDomains.js +6 -0
  16. package/dist/ReactOidc.d.ts +17 -0
  17. package/dist/ReactOidc.d.ts.map +1 -0
  18. package/dist/ReactOidc.js +106 -0
  19. package/dist/ReactOidc.js.map +1 -0
  20. package/dist/User.d.ts +15 -0
  21. package/dist/User.d.ts.map +1 -0
  22. package/dist/User.js +48 -0
  23. package/dist/User.js.map +1 -0
  24. package/dist/core/default-component/AuthenticateError.component.d.ts +4 -0
  25. package/dist/core/default-component/AuthenticateError.component.d.ts.map +1 -0
  26. package/dist/core/default-component/AuthenticateError.component.js +32 -0
  27. package/dist/core/default-component/AuthenticateError.component.js.map +1 -0
  28. package/dist/core/default-component/Authenticating.component.d.ts +4 -0
  29. package/dist/core/default-component/Authenticating.component.d.ts.map +1 -0
  30. package/dist/core/default-component/Authenticating.component.js +32 -0
  31. package/dist/core/default-component/Authenticating.component.js.map +1 -0
  32. package/dist/core/default-component/Callback.component.d.ts +5 -0
  33. package/dist/core/default-component/Callback.component.d.ts.map +1 -0
  34. package/dist/core/default-component/Callback.component.js +118 -0
  35. package/dist/core/default-component/Callback.component.js.map +1 -0
  36. package/dist/core/default-component/Loading.component.d.ts +4 -0
  37. package/dist/core/default-component/Loading.component.d.ts.map +1 -0
  38. package/dist/core/default-component/Loading.component.js +29 -0
  39. package/dist/core/default-component/Loading.component.js.map +1 -0
  40. package/dist/core/default-component/ServiceWorkerInstall.component.d.ts +4 -0
  41. package/dist/core/default-component/ServiceWorkerInstall.component.d.ts.map +1 -0
  42. package/dist/core/default-component/ServiceWorkerInstall.component.js +122 -0
  43. package/dist/core/default-component/ServiceWorkerInstall.component.js.map +1 -0
  44. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts +4 -0
  45. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -0
  46. package/dist/core/default-component/ServiceWorkerNotSupported.component.js +32 -0
  47. package/dist/core/default-component/ServiceWorkerNotSupported.component.js.map +1 -0
  48. package/dist/core/default-component/SessionLost.component.d.ts +4 -0
  49. package/dist/core/default-component/SessionLost.component.d.ts.map +1 -0
  50. package/dist/core/default-component/SessionLost.component.js +14 -0
  51. package/dist/core/default-component/SessionLost.component.js.map +1 -0
  52. package/dist/core/default-component/SilentCallback.component.d.ts +4 -0
  53. package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -0
  54. package/dist/core/default-component/SilentCallback.component.js +96 -0
  55. package/dist/core/default-component/SilentCallback.component.js.map +1 -0
  56. package/dist/core/default-component/index.d.ts +7 -0
  57. package/dist/core/default-component/index.d.ts.map +1 -0
  58. package/dist/core/default-component/index.js +20 -0
  59. package/dist/core/default-component/index.js.map +1 -0
  60. package/dist/core/routes/OidcRoutes.d.ts +12 -0
  61. package/dist/core/routes/OidcRoutes.d.ts.map +1 -0
  62. package/dist/core/routes/OidcRoutes.js +71 -0
  63. package/dist/core/routes/OidcRoutes.js.map +1 -0
  64. package/dist/core/routes/index.d.ts +3 -0
  65. package/dist/core/routes/index.d.ts.map +1 -0
  66. package/dist/core/routes/index.js +9 -0
  67. package/dist/core/routes/index.js.map +1 -0
  68. package/dist/core/routes/route-utils.d.ts +2 -0
  69. package/dist/core/routes/route-utils.d.ts.map +1 -0
  70. package/dist/core/routes/route-utils.js +32 -0
  71. package/dist/core/routes/route-utils.js.map +1 -0
  72. package/dist/core/routes/withRouter.d.ts +19 -0
  73. package/dist/core/routes/withRouter.d.ts.map +1 -0
  74. package/dist/core/routes/withRouter.js +33 -0
  75. package/dist/core/routes/withRouter.js.map +1 -0
  76. package/dist/index.d.ts +6 -0
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +19 -0
  79. package/dist/index.js.map +1 -0
  80. package/dist/vanilla/index.d.ts +2 -0
  81. package/dist/vanilla/index.d.ts.map +1 -0
  82. package/dist/vanilla/index.js +6 -0
  83. package/dist/vanilla/index.js.map +1 -0
  84. package/dist/vanilla/initSession.d.ts +11 -0
  85. package/dist/vanilla/initSession.d.ts.map +1 -0
  86. package/dist/vanilla/initSession.js +72 -0
  87. package/dist/vanilla/initSession.js.map +1 -0
  88. package/dist/vanilla/initWorker.d.ts +13 -0
  89. package/dist/vanilla/initWorker.d.ts.map +1 -0
  90. package/dist/vanilla/initWorker.js +211 -0
  91. package/dist/vanilla/initWorker.js.map +1 -0
  92. package/dist/vanilla/memoryStorageBackend.d.ts +10 -0
  93. package/dist/vanilla/memoryStorageBackend.d.ts.map +1 -0
  94. package/dist/vanilla/memoryStorageBackend.js +33 -0
  95. package/dist/vanilla/memoryStorageBackend.js.map +1 -0
  96. package/dist/vanilla/noHashQueryStringUtils.d.ts +5 -0
  97. package/dist/vanilla/noHashQueryStringUtils.d.ts.map +1 -0
  98. package/dist/vanilla/noHashQueryStringUtils.js +31 -0
  99. package/dist/vanilla/noHashQueryStringUtils.js.map +1 -0
  100. package/dist/vanilla/oidc.d.ts +77 -0
  101. package/dist/vanilla/oidc.d.ts.map +1 -0
  102. package/dist/vanilla/oidc.js +814 -0
  103. package/dist/vanilla/oidc.js.map +1 -0
  104. package/dist/vanilla/timer.d.ts +8 -0
  105. package/dist/vanilla/timer.d.ts.map +1 -0
  106. package/dist/vanilla/timer.js +135 -0
  107. package/dist/vanilla/timer.js.map +1 -0
  108. package/package.json +73 -0
  109. package/src/App.css +38 -0
  110. package/src/App.specold.tsx +46 -0
  111. package/src/App.tsx +61 -0
  112. package/src/FetchUser.tsx +53 -0
  113. package/src/Home.tsx +20 -0
  114. package/src/MultiAuth.tsx +114 -0
  115. package/src/Profile.tsx +77 -0
  116. package/src/configurations.ts +53 -0
  117. package/src/index.css +13 -0
  118. package/src/index.tsx +9 -0
  119. package/src/logo.svg +7 -0
  120. package/src/oidc/FetchToken.tsx +51 -0
  121. package/src/oidc/OidcProvider.tsx +165 -0
  122. package/src/oidc/OidcSecure.tsx +32 -0
  123. package/src/oidc/ReactOidc.tsx +112 -0
  124. package/src/oidc/User.ts +38 -0
  125. package/src/oidc/core/default-component/AuthenticateError.component.tsx +13 -0
  126. package/src/oidc/core/default-component/Authenticating.component.tsx +13 -0
  127. package/src/oidc/core/default-component/Callback.component.tsx +49 -0
  128. package/src/oidc/core/default-component/Loading.component.tsx +10 -0
  129. package/src/oidc/core/default-component/ServiceWorkerInstall.component.tsx +51 -0
  130. package/src/oidc/core/default-component/ServiceWorkerNotSupported.component.tsx +13 -0
  131. package/src/oidc/core/default-component/SessionLost.component.tsx +14 -0
  132. package/src/oidc/core/default-component/SilentCallback.component.tsx +31 -0
  133. package/src/oidc/core/default-component/index.ts +6 -0
  134. package/src/oidc/core/routes/OidcRoutes.spec.tsx +16 -0
  135. package/src/oidc/core/routes/OidcRoutes.tsx +69 -0
  136. package/src/oidc/core/routes/__snapshots__/OidcRoutes.spec.tsx.snap +7 -0
  137. package/src/oidc/core/routes/index.ts +2 -0
  138. package/src/oidc/core/routes/route-utils.spec.ts +9 -0
  139. package/src/oidc/core/routes/route-utils.ts +34 -0
  140. package/src/oidc/core/routes/withRouter.spec.tsx +48 -0
  141. package/src/oidc/core/routes/withRouter.tsx +60 -0
  142. package/src/oidc/index.ts +5 -0
  143. package/src/oidc/vanilla/OidcServiceWorker.js +272 -0
  144. package/src/oidc/vanilla/OidcTrustedDomains.js +6 -0
  145. package/src/oidc/vanilla/index.ts +1 -0
  146. package/src/oidc/vanilla/initSession.ts +36 -0
  147. package/src/oidc/vanilla/initWorker.ts +153 -0
  148. package/src/oidc/vanilla/memoryStorageBackend.ts +33 -0
  149. package/src/oidc/vanilla/noHashQueryStringUtils.ts +7 -0
  150. package/src/oidc/vanilla/oidc.ts +600 -0
  151. package/src/oidc/vanilla/timer.ts +157 -0
  152. package/src/override/AuthenticateError.component.tsx +14 -0
  153. package/src/override/Authenticating.component.tsx +14 -0
  154. package/src/override/Callback.component.tsx +13 -0
  155. package/src/override/Loading.component.tsx +13 -0
  156. package/src/override/ServiceWorkerNotSupported.component.tsx +15 -0
  157. package/src/override/SessionLost.component.tsx +21 -0
  158. package/src/override/style.ts +10 -0
  159. package/src/setupTests.js +5 -0
  160. package/tsconfig.json +38 -0
@@ -0,0 +1,814 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.Oidc = void 0;
54
+ var appauth_1 = require("@openid/appauth");
55
+ var noHashQueryStringUtils_1 = require("./noHashQueryStringUtils");
56
+ var initWorker_1 = require("./initWorker");
57
+ var memoryStorageBackend_1 = require("./memoryStorageBackend");
58
+ var initSession_1 = require("./initSession");
59
+ var timer_1 = __importDefault(require("./timer"));
60
+ var isInIframe = function () {
61
+ try {
62
+ return window.self !== window.top;
63
+ }
64
+ catch (e) {
65
+ return true;
66
+ }
67
+ };
68
+ var idTokenPayload = function (token) {
69
+ var base64Url = token.split('.')[1];
70
+ var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
71
+ var jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
72
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
73
+ }).join(''));
74
+ return JSON.parse(jsonPayload);
75
+ };
76
+ var countLetter = function (str, find) {
77
+ return (str.split(find)).length - 1;
78
+ };
79
+ var extractAccessTokenPayload = function (tokens) {
80
+ if (tokens.accessTokenPayload) {
81
+ return tokens.accessTokenPayload;
82
+ }
83
+ var accessToken = tokens.accessToken;
84
+ try {
85
+ if (!accessToken || countLetter(accessToken, '.') === 2) {
86
+ return null;
87
+ }
88
+ return JSON.parse(atob(accessToken.split('.')[1]));
89
+ }
90
+ catch (e) {
91
+ console.warn(e);
92
+ }
93
+ return null;
94
+ };
95
+ var refresh_token_scope = "offline_access";
96
+ var oidcDatabase = {};
97
+ var oidcFactory = function (configuration, name) {
98
+ if (name === void 0) { name = "default"; }
99
+ if (oidcDatabase[name]) {
100
+ return oidcDatabase[name];
101
+ }
102
+ oidcDatabase[name] = new Oidc(configuration, name);
103
+ return oidcDatabase[name];
104
+ };
105
+ var loginCallbackWithAutoTokensRenewAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, function () {
106
+ var response, tokens, _a, _b;
107
+ return __generator(this, function (_c) {
108
+ switch (_c.label) {
109
+ case 0: return [4 /*yield*/, oidc.loginCallbackAsync()];
110
+ case 1:
111
+ response = _c.sent();
112
+ tokens = response.tokens;
113
+ _a = oidc;
114
+ return [4 /*yield*/, setTokensAsync(oidc.serviceWorker, tokens)];
115
+ case 2:
116
+ _a.tokens = _c.sent();
117
+ if (!!oidc.serviceWorker) return [3 /*break*/, 4];
118
+ return [4 /*yield*/, oidc.session.setTokens(oidc.tokens)];
119
+ case 3:
120
+ _c.sent();
121
+ _c.label = 4;
122
+ case 4:
123
+ oidc.publishEvent(Oidc.eventNames.token_aquired, oidc.tokens);
124
+ _b = oidc;
125
+ return [4 /*yield*/, autoRenewTokensAsync(oidc, tokens.refreshToken, oidc.tokens.expiresAt)];
126
+ case 5:
127
+ _b.timeoutId = _c.sent();
128
+ return [2 /*return*/, response.state];
129
+ }
130
+ });
131
+ }); };
132
+ var autoRenewTokensAsync = function (oidc, refreshToken, expiresAt) { return __awaiter(void 0, void 0, void 0, function () {
133
+ var refreshTimeBeforeTokensExpirationInSecond;
134
+ var _a;
135
+ return __generator(this, function (_b) {
136
+ refreshTimeBeforeTokensExpirationInSecond = (_a = oidc.configuration.refresh_time_before_tokens_expiration_in_second) !== null && _a !== void 0 ? _a : 60;
137
+ return [2 /*return*/, timer_1.default.setTimeout(function () { return __awaiter(void 0, void 0, void 0, function () {
138
+ var currentTimeUnixSecond, timeInfo, tokens, _a, _b, _c;
139
+ return __generator(this, function (_d) {
140
+ switch (_d.label) {
141
+ case 0:
142
+ currentTimeUnixSecond = new Date().getTime() / 1000;
143
+ timeInfo = { timeLeft: ((expiresAt - refreshTimeBeforeTokensExpirationInSecond) - currentTimeUnixSecond) };
144
+ oidc.publishEvent(Oidc.eventNames.token_timer, timeInfo);
145
+ if (!(currentTimeUnixSecond > (expiresAt - refreshTimeBeforeTokensExpirationInSecond))) return [3 /*break*/, 6];
146
+ return [4 /*yield*/, oidc.refreshTokensAsync(refreshToken)];
147
+ case 1:
148
+ tokens = _d.sent();
149
+ _a = oidc;
150
+ return [4 /*yield*/, setTokensAsync(oidc.serviceWorker, tokens)];
151
+ case 2:
152
+ _a.tokens = _d.sent();
153
+ if (!!oidc.serviceWorker) return [3 /*break*/, 4];
154
+ return [4 /*yield*/, oidc.session.setTokens(oidc.tokens)];
155
+ case 3:
156
+ _d.sent();
157
+ _d.label = 4;
158
+ case 4:
159
+ if (!oidc.tokens) {
160
+ return [2 /*return*/];
161
+ }
162
+ oidc.publishEvent(Oidc.eventNames.token_renewed, oidc.tokens);
163
+ _b = oidc;
164
+ return [4 /*yield*/, autoRenewTokensAsync(oidc, tokens.refreshToken, oidc.tokens.expiresAt)];
165
+ case 5:
166
+ _b.timeoutId = _d.sent();
167
+ return [3 /*break*/, 8];
168
+ case 6:
169
+ _c = oidc;
170
+ return [4 /*yield*/, autoRenewTokensAsync(oidc, refreshToken, expiresAt)];
171
+ case 7:
172
+ _c.timeoutId = _d.sent();
173
+ _d.label = 8;
174
+ case 8: return [2 /*return*/];
175
+ }
176
+ });
177
+ }); }, 1000)];
178
+ });
179
+ }); };
180
+ var userInfoAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, function () {
181
+ var accessToken, oidcServerConfiguration, url, fetchUserInfo, userInfo;
182
+ return __generator(this, function (_a) {
183
+ switch (_a.label) {
184
+ case 0:
185
+ if (oidc.userInfo != null) {
186
+ return [2 /*return*/, oidc.userInfo];
187
+ }
188
+ if (!oidc.tokens) {
189
+ return [2 /*return*/, null];
190
+ }
191
+ accessToken = oidc.tokens.accessToken;
192
+ return [4 /*yield*/, oidc.initAsync(oidc.configuration.authority, oidc.configuration.authority_configuration)];
193
+ case 1:
194
+ oidcServerConfiguration = _a.sent();
195
+ url = oidcServerConfiguration.userInfoEndpoint;
196
+ fetchUserInfo = function (accessToken) { return __awaiter(void 0, void 0, void 0, function () {
197
+ var res;
198
+ return __generator(this, function (_a) {
199
+ switch (_a.label) {
200
+ case 0: return [4 /*yield*/, fetch(url, {
201
+ headers: {
202
+ authorization: "Bearer ".concat(accessToken)
203
+ }
204
+ })];
205
+ case 1:
206
+ res = _a.sent();
207
+ if (res.status != 200) {
208
+ return [2 /*return*/, null];
209
+ }
210
+ return [2 /*return*/, res.json()];
211
+ }
212
+ });
213
+ }); };
214
+ return [4 /*yield*/, fetchUserInfo(accessToken)];
215
+ case 2:
216
+ userInfo = _a.sent();
217
+ oidc.userInfo = userInfo;
218
+ return [2 /*return*/, userInfo];
219
+ }
220
+ });
221
+ }); };
222
+ var setTokensAsync = function (serviceWorker, tokens) { return __awaiter(void 0, void 0, void 0, function () {
223
+ var accessTokenPayload, expiresAt;
224
+ return __generator(this, function (_a) {
225
+ switch (_a.label) {
226
+ case 0:
227
+ if (!(tokens == null)) return [3 /*break*/, 3];
228
+ if (!serviceWorker) return [3 /*break*/, 2];
229
+ return [4 /*yield*/, serviceWorker.clearAsync()];
230
+ case 1:
231
+ _a.sent();
232
+ _a.label = 2;
233
+ case 2: return [2 /*return*/, null];
234
+ case 3:
235
+ if (!serviceWorker) return [3 /*break*/, 5];
236
+ return [4 /*yield*/, serviceWorker.getAccessTokenPayloadAsync()];
237
+ case 4:
238
+ accessTokenPayload = _a.sent();
239
+ return [3 /*break*/, 6];
240
+ case 5:
241
+ accessTokenPayload = extractAccessTokenPayload(tokens);
242
+ _a.label = 6;
243
+ case 6:
244
+ expiresAt = tokens.issuedAt + tokens.expiresIn;
245
+ return [2 /*return*/, __assign(__assign({}, tokens), { idTokenPayload: idTokenPayload(tokens.idToken), accessTokenPayload: accessTokenPayload, expiresAt: expiresAt })];
246
+ }
247
+ });
248
+ }); };
249
+ var eventNames = {
250
+ service_worker_not_supported_by_browser: "service_worker_not_supported_by_browser",
251
+ token_aquired: "token_aquired",
252
+ token_renewed: "token_renewed",
253
+ token_timer: "token_timer",
254
+ loginAsync_begin: "loginAsync_begin",
255
+ loginAsync_error: "loginAsync_error",
256
+ loginCallbackAsync_begin: "loginCallbackAsync_begin",
257
+ loginCallbackAsync_end: "loginCallbackAsync_end",
258
+ loginCallbackAsync_error: "loginCallbackAsync_error",
259
+ refreshTokensAsync_begin: "refreshTokensAsync_begin",
260
+ refreshTokensAsync_end: "refreshTokensAsync_end",
261
+ refreshTokensAsync_error: "refreshTokensAsync_error",
262
+ refreshTokensAsync_silent_begin: "refreshTokensAsync_silent_begin",
263
+ refreshTokensAsync_silent_end: "refreshTokensAsync_silent_end",
264
+ refreshTokensAsync_silent_error: "refreshTokensAsync_silent_error",
265
+ tryKeepExistingSessionAsync_begin: "tryKeepExistingSessionAsync_begin",
266
+ tryKeepExistingSessionAsync_end: "tryKeepExistingSessionAsync_end",
267
+ tryKeepExistingSessionAsync_error: "tryKeepExistingSessionAsync_error",
268
+ silentSigninAsync_begin: "silentSigninAsync_begin",
269
+ silentSigninAsync_end: "silentSigninAsync_end",
270
+ silentSigninAsync_error: "silentSigninAsync_error",
271
+ };
272
+ var getRandomInt = function (max) {
273
+ return Math.floor(Math.random() * max);
274
+ };
275
+ var Oidc = /** @class */ (function () {
276
+ function Oidc(configuration, configurationName) {
277
+ if (configurationName === void 0) { configurationName = "default"; }
278
+ this.configuration = configuration;
279
+ this.configurationName = configurationName;
280
+ this.tokens = null;
281
+ this.userInfo = null;
282
+ this.events = [];
283
+ this.timeoutId = null;
284
+ this.serviceWorker = null;
285
+ this.session = null;
286
+ this.refreshTokensAsync.bind(this);
287
+ this.loginCallbackWithAutoTokensRenewAsync.bind(this);
288
+ this.initAsync.bind(this);
289
+ this.loginCallbackAsync.bind(this);
290
+ this.subscriveEvents.bind(this);
291
+ this.removeEventSubscription.bind(this);
292
+ this.publishEvent.bind(this);
293
+ this.destroyAsync.bind(this);
294
+ }
295
+ Oidc.prototype.subscriveEvents = function (func) {
296
+ var id = getRandomInt(9999999999999).toString();
297
+ this.events.push({ id: id, func: func });
298
+ return id;
299
+ };
300
+ Oidc.prototype.removeEventSubscription = function (id) {
301
+ var newEvents = this.events.filter(function (e) { return e.id === id; });
302
+ this.events = newEvents;
303
+ };
304
+ Oidc.prototype.publishEvent = function (eventName, data) {
305
+ this.events.forEach(function (event) {
306
+ event.func(eventName, data);
307
+ });
308
+ };
309
+ Oidc.getOrCreate = function (configuration, name) {
310
+ if (name === void 0) { name = "default"; }
311
+ return oidcFactory(configuration, name);
312
+ };
313
+ Oidc.get = function (name) {
314
+ if (name === void 0) { name = "default"; }
315
+ return oidcDatabase[name];
316
+ };
317
+ Oidc.prototype.silentSigninCallbackFromIFrame = function () {
318
+ if (this.configuration.silent_redirect_uri) {
319
+ window.top.postMessage("".concat(this.configurationName, "_oidc_tokens:").concat(JSON.stringify(this.tokens)), window.location.origin);
320
+ }
321
+ };
322
+ Oidc.prototype.silentSigninAsync = function () {
323
+ return __awaiter(this, void 0, void 0, function () {
324
+ var configuration, link, iframe, self, promise;
325
+ return __generator(this, function (_a) {
326
+ if (!this.configuration.silent_redirect_uri) {
327
+ return [2 /*return*/, Promise.resolve(null)];
328
+ }
329
+ this.publishEvent(eventNames.silentSigninAsync_begin, {});
330
+ configuration = this.configuration;
331
+ link = configuration.silent_redirect_uri;
332
+ iframe = document.createElement('iframe');
333
+ iframe.width = "0px";
334
+ iframe.height = "0px";
335
+ iframe.id = "".concat(this.configurationName, "_oidc_iframe");
336
+ iframe.setAttribute("src", link);
337
+ document.body.appendChild(iframe);
338
+ self = this;
339
+ promise = new Promise(function (resolve, reject) {
340
+ try {
341
+ var isResolved_1 = false;
342
+ window.onmessage = function (e) {
343
+ var key = "".concat(self.configurationName, "_oidc_tokens:");
344
+ if (e.data && typeof (e.data) === "string" && e.data.startsWith(key)) {
345
+ if (!isResolved_1) {
346
+ self.publishEvent(eventNames.silentSigninAsync_end, {});
347
+ resolve(JSON.parse(e.data.replace(key, '')));
348
+ iframe.remove();
349
+ isResolved_1 = true;
350
+ }
351
+ }
352
+ };
353
+ var silentSigninTimeout = configuration.silent_signin_timeout ? configuration.silent_signin_timeout : 12000;
354
+ setTimeout(function () {
355
+ if (!isResolved_1) {
356
+ reject("timeout");
357
+ self.publishEvent(eventNames.silentSigninAsync_error, new Error("timeout"));
358
+ iframe.remove();
359
+ isResolved_1 = true;
360
+ }
361
+ }, silentSigninTimeout);
362
+ }
363
+ catch (e) {
364
+ iframe.remove();
365
+ reject(e);
366
+ self.publishEvent(eventNames.silentSigninAsync_error, e);
367
+ }
368
+ });
369
+ return [2 /*return*/, promise];
370
+ });
371
+ });
372
+ };
373
+ Oidc.prototype.initAsync = function (authority, authorityConfiguration) {
374
+ return __awaiter(this, void 0, void 0, function () {
375
+ return __generator(this, function (_a) {
376
+ switch (_a.label) {
377
+ case 0:
378
+ if (authorityConfiguration != null) {
379
+ return [2 /*return*/, new appauth_1.AuthorizationServiceConfiguration({
380
+ authorization_endpoint: authorityConfiguration.authorization_endpoint,
381
+ end_session_endpoint: authorityConfiguration.end_session_endpoint,
382
+ revocation_endpoint: authorityConfiguration.revocation_endpoint,
383
+ token_endpoint: authorityConfiguration.token_endpoint,
384
+ userinfo_endpoint: authorityConfiguration.userinfo_endpoint
385
+ })];
386
+ }
387
+ return [4 /*yield*/, appauth_1.AuthorizationServiceConfiguration.fetchFromIssuer(authority, new appauth_1.FetchRequestor())];
388
+ case 1: return [2 /*return*/, _a.sent()];
389
+ }
390
+ });
391
+ });
392
+ };
393
+ Oidc.prototype.tryKeepExistingSessionAsync = function () {
394
+ return __awaiter(this, void 0, void 0, function () {
395
+ var serviceWorker, configuration, oidcServerConfiguration, tokens, updatedTokens, _a, _b, session, tokens, updatedTokens, _c, _d, exception_1;
396
+ return __generator(this, function (_e) {
397
+ switch (_e.label) {
398
+ case 0:
399
+ if (this.tokens != null) {
400
+ return [2 /*return*/, false];
401
+ }
402
+ this.publishEvent(eventNames.tryKeepExistingSessionAsync_begin, {});
403
+ _e.label = 1;
404
+ case 1:
405
+ _e.trys.push([1, 15, , 18]);
406
+ configuration = this.configuration;
407
+ return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
408
+ case 2:
409
+ oidcServerConfiguration = _e.sent();
410
+ return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName)];
411
+ case 3:
412
+ serviceWorker = _e.sent();
413
+ if (!serviceWorker) return [3 /*break*/, 9];
414
+ return [4 /*yield*/, serviceWorker.initAsync(oidcServerConfiguration, "tryKeepExistingSessionAsync")];
415
+ case 4:
416
+ tokens = (_e.sent()).tokens;
417
+ if (!tokens) return [3 /*break*/, 8];
418
+ serviceWorker.startKeepAliveServiceWorker();
419
+ return [4 /*yield*/, this.refreshTokensAsync(tokens.refresh_token, true)];
420
+ case 5:
421
+ updatedTokens = _e.sent();
422
+ // @ts-ignore
423
+ _a = this;
424
+ return [4 /*yield*/, setTokensAsync(serviceWorker, updatedTokens)];
425
+ case 6:
426
+ // @ts-ignore
427
+ _a.tokens = _e.sent();
428
+ this.serviceWorker = serviceWorker;
429
+ // @ts-ignore
430
+ _b = this;
431
+ return [4 /*yield*/, autoRenewTokensAsync(this, updatedTokens.refreshToken, this.tokens.expiresAt)];
432
+ case 7:
433
+ // @ts-ignore
434
+ _b.timeoutId = _e.sent();
435
+ this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, { success: true, message: "tokens inside ServiceWorker are valid" });
436
+ return [2 /*return*/, true];
437
+ case 8:
438
+ this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, { success: false, message: "no exiting session found" });
439
+ return [3 /*break*/, 14];
440
+ case 9:
441
+ if (configuration.service_worker_relative_url) {
442
+ this.publishEvent(eventNames.service_worker_not_supported_by_browser, {
443
+ message: "service worker is not supported by this browser"
444
+ });
445
+ }
446
+ session = (0, initSession_1.initSession)(this.configurationName);
447
+ return [4 /*yield*/, session.initAsync()];
448
+ case 10:
449
+ tokens = (_e.sent()).tokens;
450
+ if (!tokens) return [3 /*break*/, 14];
451
+ return [4 /*yield*/, this.refreshTokensAsync(tokens.refreshToken, true)];
452
+ case 11:
453
+ updatedTokens = _e.sent();
454
+ // @ts-ignore
455
+ _c = this;
456
+ return [4 /*yield*/, setTokensAsync(serviceWorker, updatedTokens)];
457
+ case 12:
458
+ // @ts-ignore
459
+ _c.tokens = _e.sent();
460
+ session.setTokens(this.tokens);
461
+ this.session = session;
462
+ // @ts-ignore
463
+ _d = this;
464
+ return [4 /*yield*/, autoRenewTokensAsync(this, updatedTokens.refreshToken, this.tokens.expiresAt)];
465
+ case 13:
466
+ // @ts-ignore
467
+ _d.timeoutId = _e.sent();
468
+ this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, { success: true, message: "tokens inside ServiceWorker are valid" });
469
+ return [2 /*return*/, true];
470
+ case 14:
471
+ this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, { success: false, message: "no service worker" });
472
+ return [2 /*return*/, false];
473
+ case 15:
474
+ exception_1 = _e.sent();
475
+ if (!serviceWorker) return [3 /*break*/, 17];
476
+ return [4 /*yield*/, serviceWorker.clearAsync()];
477
+ case 16:
478
+ _e.sent();
479
+ _e.label = 17;
480
+ case 17:
481
+ this.publishEvent(eventNames.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid");
482
+ return [2 /*return*/, false];
483
+ case 18: return [2 /*return*/];
484
+ }
485
+ });
486
+ });
487
+ };
488
+ Oidc.prototype.loginAsync = function (callbackPath, extras, installServiceWorker) {
489
+ if (callbackPath === void 0) { callbackPath = undefined; }
490
+ if (extras === void 0) { extras = null; }
491
+ if (installServiceWorker === void 0) { installServiceWorker = true; }
492
+ return __awaiter(this, void 0, void 0, function () {
493
+ var location_1, url, state, configuration, serviceWorker, oidcServerConfiguration, isServiceWorkerProxyActive, storage, session, authorizationHandler, authRequest, exception_2;
494
+ return __generator(this, function (_a) {
495
+ switch (_a.label) {
496
+ case 0:
497
+ _a.trys.push([0, 8, , 9]);
498
+ location_1 = window.location;
499
+ url = callbackPath || location_1.pathname + (location_1.search || '') + (location_1.hash || '');
500
+ state = url;
501
+ this.publishEvent(eventNames.loginAsync_begin, {});
502
+ configuration = this.configuration;
503
+ // Security we cannot loggin from Iframe
504
+ if (!configuration.silent_redirect_uri && isInIframe()) {
505
+ throw new Error("Login from iframe is forbidden");
506
+ }
507
+ return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName)];
508
+ case 1:
509
+ serviceWorker = _a.sent();
510
+ return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
511
+ case 2:
512
+ oidcServerConfiguration = _a.sent();
513
+ if (!(serviceWorker && installServiceWorker)) return [3 /*break*/, 4];
514
+ return [4 /*yield*/, serviceWorker.isServiceWorkerProxyActiveAsync()];
515
+ case 3:
516
+ isServiceWorkerProxyActive = _a.sent();
517
+ if (!isServiceWorkerProxyActive) {
518
+ window.location.href = configuration.redirect_uri + "/service-worker-install?callbackPath=" + encodeURIComponent(url);
519
+ return [2 /*return*/];
520
+ }
521
+ _a.label = 4;
522
+ case 4:
523
+ storage = void 0;
524
+ if (!serviceWorker) return [3 /*break*/, 6];
525
+ serviceWorker.startKeepAliveServiceWorker();
526
+ return [4 /*yield*/, serviceWorker.initAsync(oidcServerConfiguration, "loginAsync")];
527
+ case 5:
528
+ _a.sent();
529
+ storage = new memoryStorageBackend_1.MemoryStorageBackend(serviceWorker.saveItemsAsync, {});
530
+ return [3 /*break*/, 7];
531
+ case 6:
532
+ session = (0, initSession_1.initSession)(this.configurationName);
533
+ storage = new memoryStorageBackend_1.MemoryStorageBackend(session.saveItemsAsync, {});
534
+ _a.label = 7;
535
+ case 7:
536
+ authorizationHandler = new appauth_1.RedirectRequestHandler(storage, new noHashQueryStringUtils_1.NoHashQueryStringUtils(), window.location, new appauth_1.DefaultCrypto());
537
+ authRequest = new appauth_1.AuthorizationRequest({
538
+ client_id: configuration.client_id,
539
+ redirect_uri: configuration.redirect_uri,
540
+ scope: configuration.scope,
541
+ response_type: appauth_1.AuthorizationRequest.RESPONSE_TYPE_CODE,
542
+ state: state,
543
+ extras: extras !== null && extras !== void 0 ? extras : configuration.extras
544
+ });
545
+ authorizationHandler.performAuthorizationRequest(oidcServerConfiguration, authRequest);
546
+ return [3 /*break*/, 9];
547
+ case 8:
548
+ exception_2 = _a.sent();
549
+ this.publishEvent(eventNames.loginAsync_error, exception_2);
550
+ throw exception_2;
551
+ case 9: return [2 /*return*/];
552
+ }
553
+ });
554
+ });
555
+ };
556
+ Oidc.prototype.loginCallbackAsync = function () {
557
+ return __awaiter(this, void 0, void 0, function () {
558
+ var configuration_1, clientId_1, redirectURL_1, authority, oidcServerConfiguration_1, serviceWorker, storage_1, items, session, items, promise, exception_3;
559
+ var _this = this;
560
+ return __generator(this, function (_a) {
561
+ switch (_a.label) {
562
+ case 0:
563
+ _a.trys.push([0, 8, , 9]);
564
+ this.publishEvent(eventNames.loginCallbackAsync_begin, {});
565
+ configuration_1 = this.configuration;
566
+ clientId_1 = configuration_1.client_id;
567
+ redirectURL_1 = configuration_1.redirect_uri;
568
+ authority = configuration_1.authority;
569
+ return [4 /*yield*/, this.initAsync(authority, configuration_1.authority_configuration)];
570
+ case 1:
571
+ oidcServerConfiguration_1 = _a.sent();
572
+ return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration_1.service_worker_relative_url, this.configurationName)];
573
+ case 2:
574
+ serviceWorker = _a.sent();
575
+ storage_1 = null;
576
+ if (!serviceWorker) return [3 /*break*/, 5];
577
+ serviceWorker.startKeepAliveServiceWorker();
578
+ this.serviceWorker = serviceWorker;
579
+ return [4 /*yield*/, serviceWorker.initAsync(oidcServerConfiguration_1, "loginCallbackAsync")];
580
+ case 3:
581
+ _a.sent();
582
+ return [4 /*yield*/, serviceWorker.loadItemsAsync()];
583
+ case 4:
584
+ items = _a.sent();
585
+ storage_1 = new memoryStorageBackend_1.MemoryStorageBackend(serviceWorker.saveItemsAsync, items);
586
+ return [3 /*break*/, 7];
587
+ case 5:
588
+ session = (0, initSession_1.initSession)(this.configurationName);
589
+ this.session = session;
590
+ return [4 /*yield*/, session.loadItemsAsync()];
591
+ case 6:
592
+ items = _a.sent();
593
+ storage_1 = new memoryStorageBackend_1.MemoryStorageBackend(session.saveItemsAsync, items);
594
+ _a.label = 7;
595
+ case 7:
596
+ promise = new Promise(function (resolve, reject) {
597
+ var tokenHandler = new appauth_1.BaseTokenRequestHandler(new appauth_1.FetchRequestor());
598
+ // @ts-ignore
599
+ var authorizationHandler = new appauth_1.RedirectRequestHandler(storage_1, new noHashQueryStringUtils_1.NoHashQueryStringUtils(), window.location, new appauth_1.DefaultCrypto());
600
+ var notifier = new appauth_1.AuthorizationNotifier();
601
+ authorizationHandler.setAuthorizationNotifier(notifier);
602
+ notifier.setAuthorizationListener(function (request, response, error) { return __awaiter(_this, void 0, void 0, function () {
603
+ var extras, _i, _a, _b, key, value, tokenRequest, tokenResponse, exception_4;
604
+ return __generator(this, function (_c) {
605
+ switch (_c.label) {
606
+ case 0:
607
+ if (error) {
608
+ reject(error);
609
+ }
610
+ if (!response) {
611
+ return [2 /*return*/];
612
+ }
613
+ extras = null;
614
+ if (request && request.internal) {
615
+ extras = {};
616
+ extras.code_verifier = request.internal.code_verifier;
617
+ if (configuration_1.token_request_extras) {
618
+ for (_i = 0, _a = Object.entries(configuration_1.token_request_extras); _i < _a.length; _i++) {
619
+ _b = _a[_i], key = _b[0], value = _b[1];
620
+ extras[key] = value;
621
+ }
622
+ }
623
+ }
624
+ tokenRequest = new appauth_1.TokenRequest({
625
+ client_id: clientId_1,
626
+ redirect_uri: redirectURL_1,
627
+ grant_type: appauth_1.GRANT_TYPE_AUTHORIZATION_CODE,
628
+ code: response.code,
629
+ refresh_token: undefined,
630
+ extras: extras,
631
+ });
632
+ _c.label = 1;
633
+ case 1:
634
+ _c.trys.push([1, 3, , 4]);
635
+ return [4 /*yield*/, tokenHandler.performTokenRequest(oidcServerConfiguration_1, tokenRequest)];
636
+ case 2:
637
+ tokenResponse = _c.sent();
638
+ resolve({ tokens: tokenResponse, state: request.state });
639
+ this.publishEvent(eventNames.loginCallbackAsync_end, {});
640
+ return [3 /*break*/, 4];
641
+ case 3:
642
+ exception_4 = _c.sent();
643
+ this.publishEvent(eventNames.loginCallbackAsync_error, exception_4);
644
+ console.error(exception_4);
645
+ reject(exception_4);
646
+ return [3 /*break*/, 4];
647
+ case 4: return [2 /*return*/];
648
+ }
649
+ });
650
+ }); });
651
+ authorizationHandler.completeAuthorizationRequestIfPossible();
652
+ });
653
+ return [2 /*return*/, promise];
654
+ case 8:
655
+ exception_3 = _a.sent();
656
+ console.error(exception_3);
657
+ this.publishEvent(eventNames.loginCallbackAsync_error, exception_3);
658
+ throw exception_3;
659
+ case 9: return [2 /*return*/];
660
+ }
661
+ });
662
+ });
663
+ };
664
+ Oidc.prototype.refreshTokensAsync = function (refreshToken, silentEvent) {
665
+ if (silentEvent === void 0) { silentEvent = false; }
666
+ return __awaiter(this, void 0, void 0, function () {
667
+ var localSilentSigninAsync, configuration, clientId, redirectUri, authority, tokenHandler, extras, _i, _a, _b, key, value, request, oidcServerConfiguration, token_response, exception_5;
668
+ var _this = this;
669
+ return __generator(this, function (_c) {
670
+ switch (_c.label) {
671
+ case 0:
672
+ localSilentSigninAsync = function (exception) {
673
+ if (exception === void 0) { exception = null; }
674
+ return __awaiter(_this, void 0, void 0, function () {
675
+ var silent_token_response, exceptionSilent_1;
676
+ return __generator(this, function (_a) {
677
+ switch (_a.label) {
678
+ case 0:
679
+ _a.trys.push([0, 2, , 3]);
680
+ return [4 /*yield*/, this.silentSigninAsync()];
681
+ case 1:
682
+ silent_token_response = _a.sent();
683
+ if (silent_token_response) {
684
+ return [2 /*return*/, silent_token_response];
685
+ }
686
+ return [3 /*break*/, 3];
687
+ case 2:
688
+ exceptionSilent_1 = _a.sent();
689
+ console.error(exceptionSilent_1);
690
+ return [3 /*break*/, 3];
691
+ case 3:
692
+ this.publishEvent(silentEvent ? eventNames.refreshTokensAsync_silent_error : eventNames.refreshTokensAsync_error, exception);
693
+ return [2 /*return*/, null];
694
+ }
695
+ });
696
+ });
697
+ };
698
+ _c.label = 1;
699
+ case 1:
700
+ _c.trys.push([1, 6, , 8]);
701
+ this.publishEvent(silentEvent ? eventNames.refreshTokensAsync_silent_begin : eventNames.refreshTokensAsync_begin, {});
702
+ configuration = this.configuration;
703
+ clientId = configuration.client_id;
704
+ redirectUri = configuration.redirect_uri;
705
+ authority = configuration.authority;
706
+ if (!!configuration.scope.split(" ").find(function (s) { return s === refresh_token_scope; })) return [3 /*break*/, 3];
707
+ return [4 /*yield*/, localSilentSigninAsync()];
708
+ case 2: return [2 /*return*/, _c.sent()];
709
+ case 3:
710
+ tokenHandler = new appauth_1.BaseTokenRequestHandler(new appauth_1.FetchRequestor());
711
+ extras = undefined;
712
+ if (configuration.token_request_extras) {
713
+ extras = {};
714
+ for (_i = 0, _a = Object.entries(configuration.token_request_extras); _i < _a.length; _i++) {
715
+ _b = _a[_i], key = _b[0], value = _b[1];
716
+ extras[key] = value;
717
+ }
718
+ }
719
+ request = new appauth_1.TokenRequest({
720
+ client_id: clientId,
721
+ redirect_uri: redirectUri,
722
+ grant_type: appauth_1.GRANT_TYPE_REFRESH_TOKEN,
723
+ code: undefined,
724
+ refresh_token: refreshToken,
725
+ extras: extras
726
+ });
727
+ return [4 /*yield*/, this.initAsync(authority, configuration.authority_configuration)];
728
+ case 4:
729
+ oidcServerConfiguration = _c.sent();
730
+ return [4 /*yield*/, tokenHandler.performTokenRequest(oidcServerConfiguration, request)];
731
+ case 5:
732
+ token_response = _c.sent();
733
+ this.publishEvent(silentEvent ? eventNames.refreshTokensAsync_silent_end : eventNames.refreshTokensAsync_end, token_response);
734
+ return [2 /*return*/, token_response];
735
+ case 6:
736
+ exception_5 = _c.sent();
737
+ console.error(exception_5);
738
+ return [4 /*yield*/, localSilentSigninAsync(exception_5)];
739
+ case 7: return [2 /*return*/, _c.sent()];
740
+ case 8: return [2 /*return*/];
741
+ }
742
+ });
743
+ });
744
+ };
745
+ Oidc.prototype.loginCallbackWithAutoTokensRenewAsync = function () {
746
+ return loginCallbackWithAutoTokensRenewAsync(this);
747
+ };
748
+ Oidc.prototype.userInfoAsync = function () {
749
+ return userInfoAsync(this);
750
+ };
751
+ Oidc.prototype.destroyAsync = function () {
752
+ return __awaiter(this, void 0, void 0, function () {
753
+ return __generator(this, function (_a) {
754
+ switch (_a.label) {
755
+ case 0:
756
+ if (!this.serviceWorker) return [3 /*break*/, 2];
757
+ return [4 /*yield*/, this.serviceWorker.clearAsync()];
758
+ case 1:
759
+ _a.sent();
760
+ _a.label = 2;
761
+ case 2:
762
+ if (!this.session) return [3 /*break*/, 4];
763
+ return [4 /*yield*/, this.session.clearAsync()];
764
+ case 3:
765
+ _a.sent();
766
+ _a.label = 4;
767
+ case 4:
768
+ this.tokens = null;
769
+ this.userInfo = null;
770
+ this.events = [];
771
+ timer_1.default.clearTimeout(this.timeoutId);
772
+ return [2 /*return*/];
773
+ }
774
+ });
775
+ });
776
+ };
777
+ Oidc.prototype.logoutAsync = function (callbackPath) {
778
+ if (callbackPath === void 0) { callbackPath = undefined; }
779
+ return __awaiter(this, void 0, void 0, function () {
780
+ var configuration, oidcServerConfiguration, path, url;
781
+ return __generator(this, function (_a) {
782
+ switch (_a.label) {
783
+ case 0:
784
+ configuration = this.configuration;
785
+ return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
786
+ case 1:
787
+ oidcServerConfiguration = _a.sent();
788
+ // TODO implement real logout
789
+ if (callbackPath && (typeof callbackPath !== 'string')) {
790
+ callbackPath = undefined;
791
+ console.warn('callbackPath path is not a string');
792
+ }
793
+ path = callbackPath || location.pathname + (location.search || '') + (location.hash || '');
794
+ url = window.location.origin + path;
795
+ return [4 /*yield*/, this.destroyAsync()];
796
+ case 2:
797
+ _a.sent();
798
+ if (oidcServerConfiguration.endSessionEndpoint) {
799
+ window.location.href = oidcServerConfiguration.endSessionEndpoint + "?redirect_uri=" + encodeURI(url);
800
+ }
801
+ else {
802
+ window.location.reload();
803
+ }
804
+ return [2 /*return*/];
805
+ }
806
+ });
807
+ });
808
+ };
809
+ Oidc.eventNames = eventNames;
810
+ return Oidc;
811
+ }());
812
+ exports.Oidc = Oidc;
813
+ exports.default = Oidc;
814
+ //# sourceMappingURL=oidc.js.map