@axa-fr/oidc-client-service-worker 6.25.2-alpha949
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.
- package/dist/OidcServiceWorker.d.ts +1 -0
- package/dist/OidcServiceWorker.js +559 -0
- package/dist/OidcServiceWorker.js.map +1 -0
- package/dist/OidcTrustedDomains.js +26 -0
- package/dist/src/OidcServiceWorker.d.ts +2 -0
- package/dist/src/OidcServiceWorker.d.ts.map +1 -0
- package/dist/src/constants.d.ts +18 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/types.d.ts +87 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils/__tests__/codeVerifier.spec.d.ts +2 -0
- package/dist/src/utils/__tests__/codeVerifier.spec.d.ts.map +1 -0
- package/dist/src/utils/__tests__/domains.spec.d.ts +2 -0
- package/dist/src/utils/__tests__/domains.spec.d.ts.map +1 -0
- package/dist/src/utils/__tests__/serializeHeaders.spec.d.ts +2 -0
- package/dist/src/utils/__tests__/serializeHeaders.spec.d.ts.map +1 -0
- package/dist/src/utils/__tests__/strings.spec.d.ts +2 -0
- package/dist/src/utils/__tests__/strings.spec.d.ts.map +1 -0
- package/dist/src/utils/__tests__/testHelper.d.ts +57 -0
- package/dist/src/utils/__tests__/testHelper.d.ts.map +1 -0
- package/dist/src/utils/__tests__/tokens.spec.d.ts +2 -0
- package/dist/src/utils/__tests__/tokens.spec.d.ts.map +1 -0
- package/dist/src/utils/codeVerifier.d.ts +2 -0
- package/dist/src/utils/codeVerifier.d.ts.map +1 -0
- package/dist/src/utils/domains.d.ts +6 -0
- package/dist/src/utils/domains.d.ts.map +1 -0
- package/dist/src/utils/index.d.ts +6 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/serializeHeaders.d.ts +3 -0
- package/dist/src/utils/serializeHeaders.d.ts.map +1 -0
- package/dist/src/utils/sleep.d.ts +3 -0
- package/dist/src/utils/sleep.d.ts.map +1 -0
- package/dist/src/utils/strings.d.ts +8 -0
- package/dist/src/utils/strings.d.ts.map +1 -0
- package/dist/src/utils/tokens.d.ts +22 -0
- package/dist/src/utils/tokens.d.ts.map +1 -0
- package/package.json +72 -0
- package/src/OidcServiceWorker.ts +423 -0
- package/src/OidcTrustedDomains.js +26 -0
- package/src/constants.ts +32 -0
- package/src/types.ts +101 -0
- package/src/utils/__tests__/codeVerifier.spec.ts +13 -0
- package/src/utils/__tests__/domains.spec.ts +90 -0
- package/src/utils/__tests__/serializeHeaders.spec.ts +12 -0
- package/src/utils/__tests__/strings.spec.ts +10 -0
- package/src/utils/__tests__/testHelper.ts +346 -0
- package/src/utils/__tests__/tokens.spec.ts +90 -0
- package/src/utils/codeVerifier.ts +4 -0
- package/src/utils/domains.ts +104 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/serializeHeaders.ts +12 -0
- package/src/utils/sleep.ts +2 -0
- package/src/utils/strings.ts +9 -0
- package/src/utils/tokens.ts +207 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/OidcServiceWorker'
|
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
const scriptFilename = "OidcTrustedDomains.js";
|
|
2
|
+
const acceptAnyDomainToken = "*";
|
|
3
|
+
const TOKEN = {
|
|
4
|
+
REFRESH_TOKEN: "REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
|
|
5
|
+
ACCESS_TOKEN: "ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
|
|
6
|
+
NONCE_TOKEN: "NONCE_SECURED_BY_OIDC_SERVICE_WORKER",
|
|
7
|
+
CODE_VERIFIER: "CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER"
|
|
8
|
+
};
|
|
9
|
+
const TokenRenewMode = {
|
|
10
|
+
access_token_or_id_token_invalid: "access_token_or_id_token_invalid",
|
|
11
|
+
access_token_invalid: "access_token_invalid",
|
|
12
|
+
id_token_invalid: "id_token_invalid"
|
|
13
|
+
};
|
|
14
|
+
const openidWellknownUrlEndWith = "/.well-known/openid-configuration";
|
|
15
|
+
function checkDomain(domains, endpoint) {
|
|
16
|
+
if (!endpoint) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const domain = domains.find((domain2) => {
|
|
20
|
+
var _a;
|
|
21
|
+
let testable;
|
|
22
|
+
if (typeof domain2 === "string") {
|
|
23
|
+
testable = new RegExp(`^${domain2}`);
|
|
24
|
+
} else {
|
|
25
|
+
testable = domain2;
|
|
26
|
+
}
|
|
27
|
+
return (_a = testable.test) == null ? void 0 : _a.call(testable, endpoint);
|
|
28
|
+
});
|
|
29
|
+
if (!domain) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Domain " + endpoint + " is not trusted, please add domain in " + scriptFilename
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const getDomains = (trustedDomain, type) => {
|
|
36
|
+
if (Array.isArray(trustedDomain)) {
|
|
37
|
+
return trustedDomain;
|
|
38
|
+
}
|
|
39
|
+
return trustedDomain[`${type}Domains`] ?? trustedDomain.domains ?? [];
|
|
40
|
+
};
|
|
41
|
+
const getCurrentDatabaseDomain = (database2, url, trustedDomains2) => {
|
|
42
|
+
var _a;
|
|
43
|
+
if (url.endsWith(openidWellknownUrlEndWith)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
for (const [key, currentDatabase] of Object.entries(database2)) {
|
|
47
|
+
const oidcServerConfiguration = currentDatabase.oidcServerConfiguration;
|
|
48
|
+
if (!oidcServerConfiguration) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (oidcServerConfiguration.tokenEndpoint && url === oidcServerConfiguration.tokenEndpoint) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (oidcServerConfiguration.revocationEndpoint && url === oidcServerConfiguration.revocationEndpoint) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const trustedDomain = trustedDomains2 == null ? [] : trustedDomains2[key];
|
|
58
|
+
const domains = getDomains(trustedDomain, "accessToken");
|
|
59
|
+
const domainsToSendTokens = oidcServerConfiguration.userInfoEndpoint ? [oidcServerConfiguration.userInfoEndpoint, ...domains] : [...domains];
|
|
60
|
+
let hasToSendToken = false;
|
|
61
|
+
if (domainsToSendTokens.find((f) => f === acceptAnyDomainToken)) {
|
|
62
|
+
hasToSendToken = true;
|
|
63
|
+
} else {
|
|
64
|
+
for (let i = 0; i < domainsToSendTokens.length; i++) {
|
|
65
|
+
let domain = domainsToSendTokens[i];
|
|
66
|
+
if (typeof domain === "string") {
|
|
67
|
+
domain = new RegExp(`^${domain}`);
|
|
68
|
+
}
|
|
69
|
+
if ((_a = domain.test) == null ? void 0 : _a.call(domain, url)) {
|
|
70
|
+
hasToSendToken = true;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (hasToSendToken) {
|
|
76
|
+
if (!currentDatabase.tokens) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return currentDatabase;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
};
|
|
84
|
+
function serializeHeaders(headers) {
|
|
85
|
+
const headersObj = {};
|
|
86
|
+
for (const key of headers.keys()) {
|
|
87
|
+
if (headers.has(key)) {
|
|
88
|
+
headersObj[key] = headers.get(key);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return headersObj;
|
|
92
|
+
}
|
|
93
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
94
|
+
function countLetter(str, find) {
|
|
95
|
+
return str.split(find).length - 1;
|
|
96
|
+
}
|
|
97
|
+
function parseJwt(token) {
|
|
98
|
+
return JSON.parse(
|
|
99
|
+
b64DecodeUnicode(token.split(".")[1].replace("-", "+").replace("_", "/"))
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
function b64DecodeUnicode(str) {
|
|
103
|
+
return decodeURIComponent(
|
|
104
|
+
Array.prototype.map.call(
|
|
105
|
+
atob(str),
|
|
106
|
+
(c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)
|
|
107
|
+
).join("")
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
function computeTimeLeft(refreshTimeBeforeTokensExpirationInSecond, expiresAt) {
|
|
111
|
+
const currentTimeUnixSecond = (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
112
|
+
return Math.round(
|
|
113
|
+
expiresAt - refreshTimeBeforeTokensExpirationInSecond - currentTimeUnixSecond
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
function isTokensValid(tokens) {
|
|
117
|
+
if (!tokens) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return computeTimeLeft(0, tokens.expiresAt) > 0;
|
|
121
|
+
}
|
|
122
|
+
const extractTokenPayload = (token) => {
|
|
123
|
+
try {
|
|
124
|
+
if (!token) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
if (countLetter(token, ".") === 2) {
|
|
128
|
+
return parseJwt(token);
|
|
129
|
+
} else {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
} catch (e) {
|
|
133
|
+
console.warn(e);
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
};
|
|
137
|
+
const isTokensOidcValid = (tokens, nonce, oidcServerConfiguration) => {
|
|
138
|
+
if (tokens.idTokenPayload) {
|
|
139
|
+
const idTokenPayload = tokens.idTokenPayload;
|
|
140
|
+
if (oidcServerConfiguration.issuer !== idTokenPayload.iss) {
|
|
141
|
+
return { isValid: false, reason: "Issuer does not match" };
|
|
142
|
+
}
|
|
143
|
+
const currentTimeUnixSecond = (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
144
|
+
if (idTokenPayload.exp && idTokenPayload.exp < currentTimeUnixSecond) {
|
|
145
|
+
return { isValid: false, reason: "Token expired" };
|
|
146
|
+
}
|
|
147
|
+
const timeInSevenDays = 60 * 60 * 24 * 7;
|
|
148
|
+
if (idTokenPayload.iat && idTokenPayload.iat + timeInSevenDays < currentTimeUnixSecond) {
|
|
149
|
+
return { isValid: false, reason: "Token is used from too long time" };
|
|
150
|
+
}
|
|
151
|
+
if (nonce && idTokenPayload.nonce && idTokenPayload.nonce !== nonce) {
|
|
152
|
+
return { isValid: false, reason: "Nonce does not match" };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { isValid: true, reason: "" };
|
|
156
|
+
};
|
|
157
|
+
function _hideTokens(tokens, currentDatabaseElement, configurationName) {
|
|
158
|
+
if (!tokens.issued_at) {
|
|
159
|
+
const currentTimeUnixSecond = (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
160
|
+
tokens.issued_at = currentTimeUnixSecond;
|
|
161
|
+
}
|
|
162
|
+
const accessTokenPayload = extractTokenPayload(tokens.access_token);
|
|
163
|
+
const secureTokens = {
|
|
164
|
+
...tokens,
|
|
165
|
+
accessTokenPayload
|
|
166
|
+
};
|
|
167
|
+
if (currentDatabaseElement.hideAccessToken) {
|
|
168
|
+
secureTokens.access_token = TOKEN.ACCESS_TOKEN + "_" + configurationName;
|
|
169
|
+
}
|
|
170
|
+
tokens.accessTokenPayload = accessTokenPayload;
|
|
171
|
+
let _idTokenPayload = null;
|
|
172
|
+
if (tokens.id_token) {
|
|
173
|
+
_idTokenPayload = extractTokenPayload(tokens.id_token);
|
|
174
|
+
tokens.idTokenPayload = { ..._idTokenPayload };
|
|
175
|
+
if (_idTokenPayload.nonce && currentDatabaseElement.nonce != null) {
|
|
176
|
+
const keyNonce = TOKEN.NONCE_TOKEN + "_" + currentDatabaseElement.configurationName;
|
|
177
|
+
_idTokenPayload.nonce = keyNonce;
|
|
178
|
+
}
|
|
179
|
+
secureTokens.idTokenPayload = _idTokenPayload;
|
|
180
|
+
}
|
|
181
|
+
if (tokens.refresh_token) {
|
|
182
|
+
secureTokens.refresh_token = TOKEN.REFRESH_TOKEN + "_" + configurationName;
|
|
183
|
+
}
|
|
184
|
+
const idTokenExpiresAt = _idTokenPayload && _idTokenPayload.exp ? _idTokenPayload.exp : Number.MAX_VALUE;
|
|
185
|
+
const accessTokenExpiresAt = accessTokenPayload && accessTokenPayload.exp ? accessTokenPayload.exp : tokens.issued_at + tokens.expires_in;
|
|
186
|
+
let expiresAt;
|
|
187
|
+
const tokenRenewMode = currentDatabaseElement.oidcConfiguration.token_renew_mode;
|
|
188
|
+
if (tokenRenewMode === TokenRenewMode.access_token_invalid) {
|
|
189
|
+
expiresAt = accessTokenExpiresAt;
|
|
190
|
+
} else if (tokenRenewMode === TokenRenewMode.id_token_invalid) {
|
|
191
|
+
expiresAt = idTokenExpiresAt;
|
|
192
|
+
} else {
|
|
193
|
+
expiresAt = idTokenExpiresAt < accessTokenExpiresAt ? idTokenExpiresAt : accessTokenExpiresAt;
|
|
194
|
+
}
|
|
195
|
+
secureTokens.expiresAt = expiresAt;
|
|
196
|
+
tokens.expiresAt = expiresAt;
|
|
197
|
+
const nonce = currentDatabaseElement.nonce ? currentDatabaseElement.nonce.nonce : null;
|
|
198
|
+
const { isValid, reason } = isTokensOidcValid(
|
|
199
|
+
tokens,
|
|
200
|
+
nonce,
|
|
201
|
+
currentDatabaseElement.oidcServerConfiguration
|
|
202
|
+
);
|
|
203
|
+
if (!isValid) {
|
|
204
|
+
throw Error(`Tokens are not OpenID valid, reason: ${reason}`);
|
|
205
|
+
}
|
|
206
|
+
if (currentDatabaseElement.tokens != null && "refresh_token" in currentDatabaseElement.tokens && !("refresh_token" in tokens)) {
|
|
207
|
+
const refreshToken = currentDatabaseElement.tokens.refresh_token;
|
|
208
|
+
currentDatabaseElement.tokens = {
|
|
209
|
+
...tokens,
|
|
210
|
+
refresh_token: refreshToken
|
|
211
|
+
};
|
|
212
|
+
} else {
|
|
213
|
+
currentDatabaseElement.tokens = tokens;
|
|
214
|
+
}
|
|
215
|
+
currentDatabaseElement.status = "LOGGED_IN";
|
|
216
|
+
return secureTokens;
|
|
217
|
+
}
|
|
218
|
+
function hideTokens(currentDatabaseElement) {
|
|
219
|
+
const configurationName = currentDatabaseElement.configurationName;
|
|
220
|
+
return (response) => {
|
|
221
|
+
if (response.status !== 200) {
|
|
222
|
+
return response;
|
|
223
|
+
}
|
|
224
|
+
return response.json().then((tokens) => {
|
|
225
|
+
const secureTokens = _hideTokens(tokens, currentDatabaseElement, configurationName);
|
|
226
|
+
const body = JSON.stringify(secureTokens);
|
|
227
|
+
return new Response(body, response);
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function replaceCodeVerifier(codeVerifier, newCodeVerifier) {
|
|
232
|
+
const regex = /code_verifier=[A-Za-z0-9_-]+/i;
|
|
233
|
+
return codeVerifier.replace(regex, `code_verifier=${newCodeVerifier}`);
|
|
234
|
+
}
|
|
235
|
+
const _self = self;
|
|
236
|
+
_self.importScripts(scriptFilename);
|
|
237
|
+
const id = Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3).toString();
|
|
238
|
+
const keepAliveJsonFilename = "OidcKeepAliveServiceWorker.json";
|
|
239
|
+
const handleInstall = (event) => {
|
|
240
|
+
console.log("[OidcServiceWorker] service worker installed " + id);
|
|
241
|
+
event.waitUntil(_self.skipWaiting());
|
|
242
|
+
};
|
|
243
|
+
const handleActivate = (event) => {
|
|
244
|
+
console.log("[OidcServiceWorker] service worker activated " + id);
|
|
245
|
+
event.waitUntil(_self.clients.claim());
|
|
246
|
+
};
|
|
247
|
+
let currentLoginCallbackConfigurationName = null;
|
|
248
|
+
const database = {
|
|
249
|
+
default: {
|
|
250
|
+
configurationName: "default",
|
|
251
|
+
tokens: null,
|
|
252
|
+
status: null,
|
|
253
|
+
state: null,
|
|
254
|
+
codeVerifier: null,
|
|
255
|
+
nonce: null,
|
|
256
|
+
oidcServerConfiguration: null,
|
|
257
|
+
hideAccessToken: true
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const getCurrentDatabasesTokenEndpoint = (database2, url) => {
|
|
261
|
+
const databases = [];
|
|
262
|
+
for (const [, value] of Object.entries(database2)) {
|
|
263
|
+
if (value.oidcServerConfiguration != null && url.startsWith(value.oidcServerConfiguration.tokenEndpoint)) {
|
|
264
|
+
databases.push(value);
|
|
265
|
+
} else if (value.oidcServerConfiguration != null && value.oidcServerConfiguration.revocationEndpoint && url.startsWith(value.oidcServerConfiguration.revocationEndpoint)) {
|
|
266
|
+
databases.push(value);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return databases;
|
|
270
|
+
};
|
|
271
|
+
const keepAliveAsync = async (event) => {
|
|
272
|
+
const originalRequest = event.request;
|
|
273
|
+
const isFromVanilla = originalRequest.headers.has("oidc-vanilla");
|
|
274
|
+
const init = { status: 200, statusText: "oidc-service-worker" };
|
|
275
|
+
const response = new Response("{}", init);
|
|
276
|
+
if (!isFromVanilla) {
|
|
277
|
+
const originalRequestUrl = new URL(originalRequest.url);
|
|
278
|
+
const minSleepSeconds = Number(originalRequestUrl.searchParams.get("minSleepSeconds")) || 240;
|
|
279
|
+
for (let i = 0; i < minSleepSeconds; i++) {
|
|
280
|
+
await sleep(1e3 + Math.floor(Math.random() * 1e3));
|
|
281
|
+
const cache = await caches.open("oidc_dummy_cache");
|
|
282
|
+
await cache.put(event.request, response.clone());
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return response;
|
|
286
|
+
};
|
|
287
|
+
const handleFetch = async (event) => {
|
|
288
|
+
const originalRequest = event.request;
|
|
289
|
+
const url = originalRequest.url;
|
|
290
|
+
if (originalRequest.url.includes(keepAliveJsonFilename)) {
|
|
291
|
+
event.respondWith(keepAliveAsync(event));
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const currentDatabaseForRequestAccessToken = getCurrentDatabaseDomain(
|
|
295
|
+
database,
|
|
296
|
+
originalRequest.url,
|
|
297
|
+
trustedDomains
|
|
298
|
+
);
|
|
299
|
+
if (currentDatabaseForRequestAccessToken && currentDatabaseForRequestAccessToken.tokens && currentDatabaseForRequestAccessToken.tokens.access_token) {
|
|
300
|
+
while (currentDatabaseForRequestAccessToken.tokens && !isTokensValid(currentDatabaseForRequestAccessToken.tokens)) {
|
|
301
|
+
await sleep(200);
|
|
302
|
+
}
|
|
303
|
+
const newRequest = originalRequest.mode === "navigate" ? new Request(originalRequest, {
|
|
304
|
+
headers: {
|
|
305
|
+
...serializeHeaders(originalRequest.headers),
|
|
306
|
+
authorization: "Bearer " + currentDatabaseForRequestAccessToken.tokens.access_token
|
|
307
|
+
}
|
|
308
|
+
}) : new Request(originalRequest, {
|
|
309
|
+
headers: {
|
|
310
|
+
...serializeHeaders(originalRequest.headers),
|
|
311
|
+
authorization: "Bearer " + currentDatabaseForRequestAccessToken.tokens.access_token
|
|
312
|
+
},
|
|
313
|
+
mode: currentDatabaseForRequestAccessToken.oidcConfiguration.service_worker_convert_all_requests_to_cors ? "cors" : originalRequest.mode
|
|
314
|
+
});
|
|
315
|
+
event.waitUntil(event.respondWith(fetch(newRequest)));
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (event.request.method !== "POST") {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
let currentDatabase = null;
|
|
322
|
+
const currentDatabases = getCurrentDatabasesTokenEndpoint(
|
|
323
|
+
database,
|
|
324
|
+
originalRequest.url
|
|
325
|
+
);
|
|
326
|
+
const numberDatabase = currentDatabases.length;
|
|
327
|
+
if (numberDatabase > 0) {
|
|
328
|
+
const maPromesse = new Promise((resolve, reject) => {
|
|
329
|
+
const clonedRequest = originalRequest.clone();
|
|
330
|
+
const response = clonedRequest.text().then((actualBody) => {
|
|
331
|
+
if (actualBody.includes(TOKEN.REFRESH_TOKEN) || actualBody.includes(TOKEN.ACCESS_TOKEN)) {
|
|
332
|
+
let newBody = actualBody;
|
|
333
|
+
for (let i = 0; i < numberDatabase; i++) {
|
|
334
|
+
const currentDb = currentDatabases[i];
|
|
335
|
+
if (currentDb && currentDb.tokens != null) {
|
|
336
|
+
const keyRefreshToken = TOKEN.REFRESH_TOKEN + "_" + currentDb.configurationName;
|
|
337
|
+
if (actualBody.includes(keyRefreshToken)) {
|
|
338
|
+
newBody = newBody.replace(
|
|
339
|
+
keyRefreshToken,
|
|
340
|
+
encodeURIComponent(currentDb.tokens.refresh_token)
|
|
341
|
+
);
|
|
342
|
+
currentDatabase = currentDb;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
const keyAccessToken = TOKEN.ACCESS_TOKEN + "_" + currentDb.configurationName;
|
|
346
|
+
if (actualBody.includes(keyAccessToken)) {
|
|
347
|
+
newBody = newBody.replace(
|
|
348
|
+
keyAccessToken,
|
|
349
|
+
encodeURIComponent(currentDb.tokens.access_token)
|
|
350
|
+
);
|
|
351
|
+
currentDatabase = currentDb;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const fetchPromise = fetch(originalRequest, {
|
|
357
|
+
body: newBody,
|
|
358
|
+
method: clonedRequest.method,
|
|
359
|
+
headers: {
|
|
360
|
+
...serializeHeaders(originalRequest.headers)
|
|
361
|
+
},
|
|
362
|
+
mode: clonedRequest.mode,
|
|
363
|
+
cache: clonedRequest.cache,
|
|
364
|
+
redirect: clonedRequest.redirect,
|
|
365
|
+
referrer: clonedRequest.referrer,
|
|
366
|
+
credentials: clonedRequest.credentials,
|
|
367
|
+
integrity: clonedRequest.integrity
|
|
368
|
+
});
|
|
369
|
+
if (currentDatabase && currentDatabase.oidcServerConfiguration != null && currentDatabase.oidcServerConfiguration.revocationEndpoint && url.startsWith(
|
|
370
|
+
currentDatabase.oidcServerConfiguration.revocationEndpoint
|
|
371
|
+
)) {
|
|
372
|
+
return fetchPromise.then(async (response2) => {
|
|
373
|
+
const text = await response2.text();
|
|
374
|
+
return new Response(text, response2);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return fetchPromise.then(hideTokens(currentDatabase));
|
|
378
|
+
} else if (actualBody.includes("code_verifier=") && currentLoginCallbackConfigurationName) {
|
|
379
|
+
currentDatabase = database[currentLoginCallbackConfigurationName];
|
|
380
|
+
currentLoginCallbackConfigurationName = null;
|
|
381
|
+
let newBody = actualBody;
|
|
382
|
+
if (currentDatabase && currentDatabase.codeVerifier != null) {
|
|
383
|
+
newBody = replaceCodeVerifier(newBody, currentDatabase.codeVerifier);
|
|
384
|
+
}
|
|
385
|
+
return fetch(originalRequest, {
|
|
386
|
+
body: newBody,
|
|
387
|
+
method: clonedRequest.method,
|
|
388
|
+
headers: {
|
|
389
|
+
...serializeHeaders(originalRequest.headers)
|
|
390
|
+
},
|
|
391
|
+
mode: clonedRequest.mode,
|
|
392
|
+
cache: clonedRequest.cache,
|
|
393
|
+
redirect: clonedRequest.redirect,
|
|
394
|
+
referrer: clonedRequest.referrer,
|
|
395
|
+
credentials: clonedRequest.credentials,
|
|
396
|
+
integrity: clonedRequest.integrity
|
|
397
|
+
}).then(hideTokens(currentDatabase));
|
|
398
|
+
}
|
|
399
|
+
return void 0;
|
|
400
|
+
});
|
|
401
|
+
response.then((r) => {
|
|
402
|
+
if (r !== void 0) {
|
|
403
|
+
resolve(r);
|
|
404
|
+
} else {
|
|
405
|
+
console.log("success undefined");
|
|
406
|
+
reject(new Error("Response is undefined inside a success"));
|
|
407
|
+
}
|
|
408
|
+
}).catch((err) => {
|
|
409
|
+
if (err !== void 0) {
|
|
410
|
+
reject(err);
|
|
411
|
+
} else {
|
|
412
|
+
console.log("error undefined");
|
|
413
|
+
reject(new Error("Response is undefined inside a error"));
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
event.waitUntil(event.respondWith(maPromesse));
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
const trustedDomainsShowAccessToken = {};
|
|
421
|
+
const handleMessage = (event) => {
|
|
422
|
+
const port = event.ports[0];
|
|
423
|
+
const data = event.data;
|
|
424
|
+
const configurationName = data.configurationName;
|
|
425
|
+
let currentDatabase = database[configurationName];
|
|
426
|
+
if (trustedDomains == null) {
|
|
427
|
+
trustedDomains = {};
|
|
428
|
+
}
|
|
429
|
+
if (!currentDatabase) {
|
|
430
|
+
if (trustedDomainsShowAccessToken[configurationName] === void 0) {
|
|
431
|
+
const trustedDomain = trustedDomains[configurationName];
|
|
432
|
+
trustedDomainsShowAccessToken[configurationName] = Array.isArray(trustedDomain) ? false : trustedDomain.showAccessToken;
|
|
433
|
+
}
|
|
434
|
+
database[configurationName] = {
|
|
435
|
+
tokens: null,
|
|
436
|
+
state: null,
|
|
437
|
+
codeVerifier: null,
|
|
438
|
+
oidcServerConfiguration: null,
|
|
439
|
+
oidcConfiguration: void 0,
|
|
440
|
+
nonce: null,
|
|
441
|
+
status: null,
|
|
442
|
+
configurationName,
|
|
443
|
+
hideAccessToken: !trustedDomainsShowAccessToken[configurationName]
|
|
444
|
+
};
|
|
445
|
+
currentDatabase = database[configurationName];
|
|
446
|
+
if (!trustedDomains[configurationName]) {
|
|
447
|
+
trustedDomains[configurationName] = [];
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
switch (data.type) {
|
|
451
|
+
case "clear":
|
|
452
|
+
currentDatabase.tokens = null;
|
|
453
|
+
currentDatabase.state = null;
|
|
454
|
+
currentDatabase.codeVerifier = null;
|
|
455
|
+
currentDatabase.status = data.data.status;
|
|
456
|
+
port.postMessage({ configurationName });
|
|
457
|
+
return;
|
|
458
|
+
case "init": {
|
|
459
|
+
const oidcServerConfiguration = data.data.oidcServerConfiguration;
|
|
460
|
+
const trustedDomain = trustedDomains[configurationName];
|
|
461
|
+
const domains = getDomains(trustedDomain, "oidc");
|
|
462
|
+
if (!domains.find((f) => f === acceptAnyDomainToken)) {
|
|
463
|
+
[
|
|
464
|
+
oidcServerConfiguration.tokenEndpoint,
|
|
465
|
+
oidcServerConfiguration.revocationEndpoint,
|
|
466
|
+
oidcServerConfiguration.userInfoEndpoint,
|
|
467
|
+
oidcServerConfiguration.issuer
|
|
468
|
+
].forEach((url) => {
|
|
469
|
+
checkDomain(domains, url);
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
currentDatabase.oidcServerConfiguration = oidcServerConfiguration;
|
|
473
|
+
currentDatabase.oidcConfiguration = data.data.oidcConfiguration;
|
|
474
|
+
const where = data.data.where;
|
|
475
|
+
if (where === "loginCallbackAsync" || where === "tryKeepExistingSessionAsync") {
|
|
476
|
+
currentLoginCallbackConfigurationName = configurationName;
|
|
477
|
+
} else {
|
|
478
|
+
currentLoginCallbackConfigurationName = null;
|
|
479
|
+
}
|
|
480
|
+
if (!currentDatabase.tokens) {
|
|
481
|
+
port.postMessage({
|
|
482
|
+
tokens: null,
|
|
483
|
+
status: currentDatabase.status,
|
|
484
|
+
configurationName
|
|
485
|
+
});
|
|
486
|
+
} else {
|
|
487
|
+
const tokens = {
|
|
488
|
+
...currentDatabase.tokens
|
|
489
|
+
};
|
|
490
|
+
if (currentDatabase.hideAccessToken) {
|
|
491
|
+
tokens.access_token = TOKEN.ACCESS_TOKEN + "_" + configurationName;
|
|
492
|
+
}
|
|
493
|
+
if (tokens.refresh_token) {
|
|
494
|
+
tokens.refresh_token = TOKEN.REFRESH_TOKEN + "_" + configurationName;
|
|
495
|
+
}
|
|
496
|
+
if (tokens.idTokenPayload && tokens.idTokenPayload.nonce && currentDatabase.nonce != null) {
|
|
497
|
+
tokens.idTokenPayload.nonce = TOKEN.NONCE_TOKEN + "_" + configurationName;
|
|
498
|
+
}
|
|
499
|
+
port.postMessage({
|
|
500
|
+
tokens,
|
|
501
|
+
status: currentDatabase.status,
|
|
502
|
+
configurationName
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
case "setState":
|
|
508
|
+
currentDatabase.state = data.data.state;
|
|
509
|
+
port.postMessage({ configurationName });
|
|
510
|
+
return;
|
|
511
|
+
case "getState": {
|
|
512
|
+
const state = currentDatabase.state;
|
|
513
|
+
port.postMessage({ configurationName, state });
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
case "setCodeVerifier":
|
|
517
|
+
currentDatabase.codeVerifier = data.data.codeVerifier;
|
|
518
|
+
port.postMessage({ configurationName });
|
|
519
|
+
return;
|
|
520
|
+
case "getCodeVerifier": {
|
|
521
|
+
port.postMessage({
|
|
522
|
+
configurationName,
|
|
523
|
+
codeVerifier: currentDatabase.codeVerifier != null ? TOKEN.CODE_VERIFIER + "_" + configurationName : null
|
|
524
|
+
});
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
case "setSessionState":
|
|
528
|
+
currentDatabase.sessionState = data.data.sessionState;
|
|
529
|
+
port.postMessage({ configurationName });
|
|
530
|
+
return;
|
|
531
|
+
case "getSessionState": {
|
|
532
|
+
const sessionState = currentDatabase.sessionState;
|
|
533
|
+
port.postMessage({ configurationName, sessionState });
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
case "setNonce": {
|
|
537
|
+
const nonce = data.data.nonce;
|
|
538
|
+
if (nonce) {
|
|
539
|
+
currentDatabase.nonce = nonce;
|
|
540
|
+
}
|
|
541
|
+
port.postMessage({ configurationName });
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
case "getNonce": {
|
|
545
|
+
const keyNonce = TOKEN.NONCE_TOKEN + "_" + configurationName;
|
|
546
|
+
const nonce = currentDatabase.nonce ? keyNonce : null;
|
|
547
|
+
port.postMessage({ configurationName, nonce });
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
default:
|
|
551
|
+
currentDatabase.items = { ...data.data };
|
|
552
|
+
port.postMessage({ configurationName });
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
_self.addEventListener("install", handleInstall);
|
|
556
|
+
_self.addEventListener("activate", handleActivate);
|
|
557
|
+
_self.addEventListener("fetch", handleFetch);
|
|
558
|
+
_self.addEventListener("message", handleMessage);
|
|
559
|
+
//# sourceMappingURL=OidcServiceWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OidcServiceWorker.js","sources":["../src/constants.ts","../src/utils/domains.ts","../src/utils/serializeHeaders.ts","../src/utils/sleep.ts","../src/utils/strings.ts","../src/utils/tokens.ts","../src/utils/codeVerifier.ts","../src/OidcServiceWorker.ts"],"sourcesContent":["const scriptFilename = 'OidcTrustedDomains.js';\nconst acceptAnyDomainToken = '*';\n\ntype TokenType = {\n readonly REFRESH_TOKEN: string;\n readonly ACCESS_TOKEN: string;\n readonly NONCE_TOKEN: string;\n readonly CODE_VERIFIER: string;\n};\n\nconst TOKEN: TokenType = {\n REFRESH_TOKEN: 'REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER',\n ACCESS_TOKEN: 'ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER',\n NONCE_TOKEN: 'NONCE_SECURED_BY_OIDC_SERVICE_WORKER',\n CODE_VERIFIER: 'CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER',\n};\n\ntype TokenRenewModeType = {\n readonly access_token_or_id_token_invalid: string;\n readonly access_token_invalid: string;\n readonly id_token_invalid: string;\n};\n\nconst TokenRenewMode: TokenRenewModeType = {\n access_token_or_id_token_invalid: 'access_token_or_id_token_invalid',\n access_token_invalid: 'access_token_invalid',\n id_token_invalid: 'id_token_invalid',\n};\n\nconst openidWellknownUrlEndWith = '/.well-known/openid-configuration';\n\nexport { acceptAnyDomainToken, openidWellknownUrlEndWith, scriptFilename, TOKEN, TokenRenewMode };\n","import {\n acceptAnyDomainToken,\n openidWellknownUrlEndWith,\n scriptFilename,\n} from '../constants';\nimport { Database, Domain, DomainDetails, OidcConfig, TrustedDomains } from '../types';\n\nfunction checkDomain(domains: Domain[], endpoint: string) {\n if (!endpoint) {\n return;\n }\n\n const domain = domains.find((domain) => {\n let testable: RegExp;\n\n if (typeof domain === 'string') {\n testable = new RegExp(`^${domain}`);\n } else {\n testable = domain;\n }\n\n return testable.test?.(endpoint);\n });\n if (!domain) {\n throw new Error(\n 'Domain ' +\n endpoint +\n ' is not trusted, please add domain in ' +\n scriptFilename,\n );\n }\n}\n\nexport const getDomains = (trustedDomain: Domain[] | DomainDetails, type: 'oidc' | 'accessToken') => {\n if (Array.isArray(trustedDomain)) {\n return trustedDomain;\n }\n\n return trustedDomain[`${type}Domains`] ?? trustedDomain.domains ?? [];\n};\n\nconst getCurrentDatabaseDomain = (\n database: Database,\n url: string,\n trustedDomains: TrustedDomains,\n) => {\n if (url.endsWith(openidWellknownUrlEndWith)) {\n return null;\n }\n for (const [key, currentDatabase] of Object.entries<OidcConfig>(database)) {\n const oidcServerConfiguration = currentDatabase.oidcServerConfiguration;\n\n if (!oidcServerConfiguration) {\n continue;\n }\n\n if (\n oidcServerConfiguration.tokenEndpoint &&\n url === oidcServerConfiguration.tokenEndpoint\n ) {\n continue;\n }\n if (\n oidcServerConfiguration.revocationEndpoint &&\n url === oidcServerConfiguration.revocationEndpoint\n ) {\n continue;\n }\n const trustedDomain = trustedDomains == null ? [] : trustedDomains[key];\n\n const domains = getDomains(trustedDomain, 'accessToken');\n const domainsToSendTokens = oidcServerConfiguration.userInfoEndpoint\n ? [oidcServerConfiguration.userInfoEndpoint, ...domains]\n : [...domains];\n\n let hasToSendToken = false;\n if (domainsToSendTokens.find((f) => f === acceptAnyDomainToken)) {\n hasToSendToken = true;\n } else {\n for (let i = 0; i < domainsToSendTokens.length; i++) {\n let domain = domainsToSendTokens[i];\n\n if (typeof domain === 'string') {\n domain = new RegExp(`^${domain}`);\n }\n\n if (domain.test?.(url)) {\n hasToSendToken = true;\n break;\n }\n }\n }\n\n if (hasToSendToken) {\n if (!currentDatabase.tokens) {\n return null;\n }\n return currentDatabase;\n }\n }\n return null;\n};\n\nexport { checkDomain, getCurrentDatabaseDomain };\n","import { FetchHeaders } from '../types';\n\nfunction serializeHeaders(headers: Headers) {\n const headersObj: Record<string, string> = {};\n for (const key of (headers as FetchHeaders).keys()) {\n if (headers.has(key)) {\n headersObj[key] = headers.get(key) as string;\n }\n }\n return headersObj;\n}\nexport { serializeHeaders };\n","const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\nexport { sleep };\n","/**\n * Count occurances of letter in string\n * @param str\n * @param find\n * @returns\n */\nexport function countLetter(str: string, find: string) {\n return str.split(find).length - 1;\n}\n","/* eslint-disable simple-import-sort/exports */\nimport { TOKEN, TokenRenewMode } from '../constants';\nimport { OidcConfig, OidcConfiguration, OidcServerConfiguration, Tokens } from '../types';\nimport { countLetter } from './strings';\n\nfunction parseJwt(token: string) {\n return JSON.parse(\n b64DecodeUnicode(token.split('.')[1].replace('-', '+').replace('_', '/')),\n );\n}\nfunction b64DecodeUnicode(str: string) {\n return decodeURIComponent(\n Array.prototype.map\n .call(\n atob(str),\n (c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2),\n )\n .join(''),\n );\n}\n\nfunction computeTimeLeft(\n refreshTimeBeforeTokensExpirationInSecond: number,\n expiresAt: number,\n) {\n const currentTimeUnixSecond = new Date().getTime() / 1000;\n return Math.round(\n expiresAt -\n refreshTimeBeforeTokensExpirationInSecond -\n currentTimeUnixSecond,\n );\n}\n\nfunction isTokensValid(tokens: Tokens | null) {\n if (!tokens) {\n return false;\n }\n return computeTimeLeft(0, tokens.expiresAt) > 0;\n}\n\nconst extractTokenPayload = (token?: string) => {\n try {\n if (!token) {\n return null;\n }\n if (countLetter(token, '.') === 2) {\n return parseJwt(token);\n } else {\n return null;\n }\n } catch (e) {\n console.warn(e);\n }\n return null;\n};\n\n// https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation (excluding rules #1, #4, #5, #7, #8, #12, and #13 which did not apply).\n// https://github.com/openid/AppAuth-JS/issues/65\nconst isTokensOidcValid = (\n tokens: Tokens,\n nonce: string | null,\n oidcServerConfiguration: OidcServerConfiguration,\n): { isValid: boolean; reason: string } => {\n if (tokens.idTokenPayload) {\n const idTokenPayload = tokens.idTokenPayload;\n // 2: The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery) MUST exactly match the value of the iss (issuer) Claim.\n if (oidcServerConfiguration.issuer !== idTokenPayload.iss) {\n return { isValid: false, reason: 'Issuer does not match' };\n }\n // 3: The Client MUST validate that the aud (audience) Claim contains its client_id value registered at the Issuer identified by the iss (issuer) Claim as an audience. The aud (audience) Claim MAY contain an array with more than one element. The ID Token MUST be rejected if the ID Token does not list the Client as a valid audience, or if it contains additional audiences not trusted by the Client.\n\n // 6: If the ID Token is received via direct communication between the Client and the Token Endpoint (which it is in this flow), the TLS server validation MAY be used to validate the issuer in place of checking the token signature. The Client MUST validate the signature of all other ID Tokens according to JWS [JWS] using the algorithm specified in the JWT alg Header Parameter. The Client MUST use the keys provided by the Issuer.\n\n // 9: The current time MUST be before the time represented by the exp Claim.\n const currentTimeUnixSecond = new Date().getTime() / 1000;\n if (idTokenPayload.exp && idTokenPayload.exp < currentTimeUnixSecond) {\n return { isValid: false, reason: 'Token expired' };\n }\n // 10: The iat Claim can be used to reject tokens that were issued too far away from the current time, limiting the amount of time that nonces need to be stored to prevent attacks. The acceptable range is Client specific.\n const timeInSevenDays = 60 * 60 * 24 * 7;\n if (\n idTokenPayload.iat &&\n idTokenPayload.iat + timeInSevenDays < currentTimeUnixSecond\n ) {\n return { isValid: false, reason: 'Token is used from too long time' };\n }\n // 11: If a nonce value was sent in the Authentication Request, a nonce Claim MUST be present and its value checked to verify that it is the same value as the one that was sent in the Authentication Request. The Client SHOULD check the nonce value for replay attacks. The precise method for detecting replay attacks is Client specific.\n if (nonce && idTokenPayload.nonce && idTokenPayload.nonce !== nonce) {\n return { isValid: false, reason: 'Nonce does not match' };\n }\n }\n return { isValid: true, reason: '' };\n};\n\nfunction _hideTokens(tokens: Tokens, currentDatabaseElement: OidcConfig, configurationName: string) {\n if (!tokens.issued_at) {\n const currentTimeUnixSecond = new Date().getTime() / 1000;\n tokens.issued_at = currentTimeUnixSecond;\n }\n\n const accessTokenPayload = extractTokenPayload(tokens.access_token);\n const secureTokens = {\n ...tokens,\n accessTokenPayload,\n };\n if (currentDatabaseElement.hideAccessToken) {\n secureTokens.access_token = TOKEN.ACCESS_TOKEN + '_' + configurationName;\n }\n tokens.accessTokenPayload = accessTokenPayload;\n\n let _idTokenPayload = null;\n if (tokens.id_token) {\n _idTokenPayload = extractTokenPayload(tokens.id_token);\n tokens.idTokenPayload = { ..._idTokenPayload };\n if (_idTokenPayload.nonce && currentDatabaseElement.nonce != null) {\n const keyNonce =\n TOKEN.NONCE_TOKEN + '_' + currentDatabaseElement.configurationName;\n _idTokenPayload.nonce = keyNonce;\n }\n secureTokens.idTokenPayload = _idTokenPayload;\n }\n if (tokens.refresh_token) {\n secureTokens.refresh_token =\n TOKEN.REFRESH_TOKEN + '_' + configurationName;\n }\n\n const idTokenExpiresAt =\n _idTokenPayload && _idTokenPayload.exp\n ? _idTokenPayload.exp\n : Number.MAX_VALUE;\n const accessTokenExpiresAt =\n accessTokenPayload && accessTokenPayload.exp\n ? accessTokenPayload.exp\n : tokens.issued_at + tokens.expires_in;\n\n let expiresAt: number;\n const tokenRenewMode = (\n currentDatabaseElement.oidcConfiguration as OidcConfiguration\n ).token_renew_mode;\n if (tokenRenewMode === TokenRenewMode.access_token_invalid) {\n expiresAt = accessTokenExpiresAt;\n } else if (tokenRenewMode === TokenRenewMode.id_token_invalid) {\n expiresAt = idTokenExpiresAt;\n } else {\n expiresAt =\n idTokenExpiresAt < accessTokenExpiresAt\n ? idTokenExpiresAt\n : accessTokenExpiresAt;\n }\n secureTokens.expiresAt = expiresAt;\n\n tokens.expiresAt = expiresAt;\n const nonce = currentDatabaseElement.nonce\n ? currentDatabaseElement.nonce.nonce\n : null;\n const { isValid, reason } = isTokensOidcValid(\n tokens,\n nonce,\n currentDatabaseElement.oidcServerConfiguration as OidcServerConfiguration,\n ); // TODO: Type assertion, could be null.\n if (!isValid) {\n throw Error(`Tokens are not OpenID valid, reason: ${reason}`);\n }\n\n // When refresh_token is not rotated we reuse ald refresh_token\n if (\n currentDatabaseElement.tokens != null &&\n 'refresh_token' in currentDatabaseElement.tokens &&\n !('refresh_token' in tokens)\n ) {\n const refreshToken = currentDatabaseElement.tokens.refresh_token;\n\n currentDatabaseElement.tokens = {\n ...tokens,\n refresh_token: refreshToken,\n };\n } else {\n currentDatabaseElement.tokens = tokens;\n }\n\n currentDatabaseElement.status = 'LOGGED_IN';\n return secureTokens;\n}\n\nfunction hideTokens(currentDatabaseElement: OidcConfig) {\n const configurationName = currentDatabaseElement.configurationName;\n return (response: Response) => {\n if (response.status !== 200) {\n return response;\n }\n return response.json().then<Response>((tokens: Tokens) => {\n const secureTokens = _hideTokens(tokens, currentDatabaseElement, configurationName);\n const body = JSON.stringify(secureTokens);\n return new Response(body, response);\n });\n };\n}\n\nexport {\n b64DecodeUnicode,\n computeTimeLeft,\n isTokensValid,\n extractTokenPayload,\n isTokensOidcValid,\n hideTokens,\n _hideTokens,\n};\n","export function replaceCodeVerifier(codeVerifier:string, newCodeVerifier:string):string {\n const regex = /code_verifier=[A-Za-z0-9_-]+/i;\n return codeVerifier.replace(regex, `code_verifier=${newCodeVerifier}`);\n}\n","import { acceptAnyDomainToken, scriptFilename, TOKEN } from './constants';\nimport {\n Database,\n MessageEventData,\n OidcConfig,\n OidcConfiguration,\n TrustedDomains,\n // TrustedDomainsShowAccessToken,\n} from './types';\nimport {\n checkDomain,\n getCurrentDatabaseDomain,\n getDomains,\n hideTokens,\n isTokensValid,\n serializeHeaders,\n sleep,\n} from './utils';\nimport { replaceCodeVerifier } from './utils/codeVerifier';\n\nconst _self = self as ServiceWorkerGlobalScope & typeof globalThis;\n\ndeclare let trustedDomains: TrustedDomains;\n\n_self.importScripts(scriptFilename);\n\nconst id = Math.round(new Date().getTime() / 1000).toString();\n\nconst keepAliveJsonFilename = 'OidcKeepAliveServiceWorker.json';\nconst handleInstall = (event: ExtendableEvent) => {\n console.log('[OidcServiceWorker] service worker installed ' + id);\n event.waitUntil(_self.skipWaiting());\n};\n\nconst handleActivate = (event: ExtendableEvent) => {\n console.log('[OidcServiceWorker] service worker activated ' + id);\n event.waitUntil(_self.clients.claim());\n};\n\nlet currentLoginCallbackConfigurationName: string | null = null;\nconst database: Database = {\n default: {\n configurationName: 'default',\n tokens: null,\n status: null,\n state: null,\n codeVerifier: null,\n nonce: null,\n oidcServerConfiguration: null,\n hideAccessToken: true,\n },\n};\n\nconst getCurrentDatabasesTokenEndpoint = (database: Database, url: string) => {\n const databases: OidcConfig[] = [];\n for (const [, value] of Object.entries<OidcConfig>(database)) {\n if (\n value.oidcServerConfiguration != null &&\n url.startsWith(value.oidcServerConfiguration.tokenEndpoint)\n ) {\n databases.push(value);\n } else if (\n value.oidcServerConfiguration != null &&\n value.oidcServerConfiguration.revocationEndpoint &&\n url.startsWith(value.oidcServerConfiguration.revocationEndpoint)\n ) {\n databases.push(value);\n }\n }\n return databases;\n};\n\nconst keepAliveAsync = async (event: FetchEvent) => {\n const originalRequest = event.request;\n const isFromVanilla = originalRequest.headers.has('oidc-vanilla');\n const init = { status: 200, statusText: 'oidc-service-worker' };\n const response = new Response('{}', init);\n if (!isFromVanilla) {\n const originalRequestUrl = new URL(originalRequest.url);\n const minSleepSeconds = Number(originalRequestUrl.searchParams.get('minSleepSeconds')) || 240;\n for (let i = 0; i < minSleepSeconds; i++) {\n await sleep(1000 + Math.floor(Math.random() * 1000));\n const cache = await caches.open('oidc_dummy_cache');\n await cache.put(event.request, response.clone());\n }\n }\n return response;\n};\n\nconst handleFetch = async (event: FetchEvent) => {\n const originalRequest = event.request;\n const url = originalRequest.url;\n if (originalRequest.url.includes(keepAliveJsonFilename)) {\n event.respondWith(keepAliveAsync(event));\n return;\n }\n\n const currentDatabaseForRequestAccessToken = getCurrentDatabaseDomain(\n database,\n originalRequest.url,\n trustedDomains,\n );\n if (\n currentDatabaseForRequestAccessToken &&\n currentDatabaseForRequestAccessToken.tokens &&\n currentDatabaseForRequestAccessToken.tokens.access_token\n ) {\n while (\n currentDatabaseForRequestAccessToken.tokens &&\n !isTokensValid(currentDatabaseForRequestAccessToken.tokens)\n ) {\n await sleep(200);\n }\n const newRequest =\n originalRequest.mode === 'navigate'\n ? new Request(originalRequest, {\n headers: {\n ...serializeHeaders(originalRequest.headers),\n authorization:\n 'Bearer ' +\n currentDatabaseForRequestAccessToken.tokens.access_token,\n },\n })\n : new Request(originalRequest, {\n headers: {\n ...serializeHeaders(originalRequest.headers),\n authorization:\n 'Bearer ' +\n currentDatabaseForRequestAccessToken.tokens.access_token,\n },\n mode: (\n currentDatabaseForRequestAccessToken.oidcConfiguration as OidcConfiguration\n ).service_worker_convert_all_requests_to_cors\n ? 'cors'\n : originalRequest.mode,\n });\n\n // @ts-ignore -- TODO: review, waitUntil takes a promise, this returns a void\n event.waitUntil(event.respondWith(fetch(newRequest)));\n\n return;\n }\n\n if (event.request.method !== 'POST') {\n return;\n }\n\n let currentDatabase: OidcConfig | null = null;\n const currentDatabases = getCurrentDatabasesTokenEndpoint(\n database,\n originalRequest.url,\n );\n const numberDatabase = currentDatabases.length;\n if (numberDatabase > 0) {\n const maPromesse = new Promise<Response>((resolve, reject) => {\n const clonedRequest = originalRequest.clone();\n const response = clonedRequest.text().then((actualBody) => {\n if (\n actualBody.includes(TOKEN.REFRESH_TOKEN) ||\n actualBody.includes(TOKEN.ACCESS_TOKEN)\n ) {\n let newBody = actualBody;\n for (let i = 0; i < numberDatabase; i++) {\n const currentDb = currentDatabases[i];\n\n if (currentDb && currentDb.tokens != null) {\n const keyRefreshToken =\n TOKEN.REFRESH_TOKEN + '_' + currentDb.configurationName;\n if (actualBody.includes(keyRefreshToken)) {\n newBody = newBody.replace(\n keyRefreshToken,\n encodeURIComponent(currentDb.tokens.refresh_token as string),\n );\n currentDatabase = currentDb;\n break;\n }\n const keyAccessToken =\n TOKEN.ACCESS_TOKEN + '_' + currentDb.configurationName;\n if (actualBody.includes(keyAccessToken)) {\n newBody = newBody.replace(\n keyAccessToken,\n encodeURIComponent(currentDb.tokens.access_token),\n );\n currentDatabase = currentDb;\n break;\n }\n }\n }\n const fetchPromise = fetch(originalRequest, {\n body: newBody,\n method: clonedRequest.method,\n headers: {\n ...serializeHeaders(originalRequest.headers),\n },\n mode: clonedRequest.mode,\n cache: clonedRequest.cache,\n redirect: clonedRequest.redirect,\n referrer: clonedRequest.referrer,\n credentials: clonedRequest.credentials,\n integrity: clonedRequest.integrity,\n });\n\n if (\n currentDatabase &&\n currentDatabase.oidcServerConfiguration != null &&\n currentDatabase.oidcServerConfiguration.revocationEndpoint &&\n url.startsWith(\n currentDatabase.oidcServerConfiguration.revocationEndpoint,\n )\n ) {\n return fetchPromise.then(async (response) => {\n const text = await response.text();\n return new Response(text, response);\n });\n }\n return fetchPromise.then(hideTokens(currentDatabase as OidcConfig)); // todo type assertion to OidcConfig but could be null, NEEDS REVIEW\n } else if (\n actualBody.includes('code_verifier=') &&\n currentLoginCallbackConfigurationName\n ) {\n currentDatabase = database[currentLoginCallbackConfigurationName];\n currentLoginCallbackConfigurationName = null;\n let newBody = actualBody;\n if (currentDatabase && currentDatabase.codeVerifier != null) {\n newBody = replaceCodeVerifier(newBody, currentDatabase.codeVerifier);\n }\n\n return fetch(originalRequest, {\n body: newBody,\n method: clonedRequest.method,\n headers: {\n ...serializeHeaders(originalRequest.headers),\n },\n mode: clonedRequest.mode,\n cache: clonedRequest.cache,\n redirect: clonedRequest.redirect,\n referrer: clonedRequest.referrer,\n credentials: clonedRequest.credentials,\n integrity: clonedRequest.integrity,\n }).then(hideTokens(currentDatabase));\n }\n return undefined;\n });\n response\n .then((r) => {\n if (r !== undefined) {\n resolve(r);\n } else {\n console.log('success undefined');\n reject(new Error('Response is undefined inside a success'));\n }\n })\n .catch((err) => {\n if (err !== undefined) {\n reject(err);\n } else {\n console.log('error undefined');\n reject(new Error('Response is undefined inside a error'));\n }\n });\n });\n\n // @ts-ignore -- TODO: review, waitUntil takes a promise, this returns a void\n event.waitUntil(event.respondWith(maPromesse));\n }\n};\n\ntype TrustedDomainsShowAccessToken = {\n [key: string]: boolean;\n}\n\nconst trustedDomainsShowAccessToken: TrustedDomainsShowAccessToken = {};\n\nconst handleMessage = (event: ExtendableMessageEvent) => {\n const port = event.ports[0];\n const data = event.data as MessageEventData;\n const configurationName = data.configurationName;\n let currentDatabase = database[configurationName];\n if (trustedDomains == null) {\n trustedDomains = {};\n }\n if (!currentDatabase) {\n if (trustedDomainsShowAccessToken[configurationName] === undefined) {\n const trustedDomain = trustedDomains[configurationName];\n trustedDomainsShowAccessToken[configurationName] = Array.isArray(trustedDomain) ? false : trustedDomain.showAccessToken;\n }\n database[configurationName] = {\n tokens: null,\n state: null,\n codeVerifier: null,\n oidcServerConfiguration: null,\n oidcConfiguration: undefined,\n nonce: null,\n status: null,\n configurationName,\n hideAccessToken: !trustedDomainsShowAccessToken[configurationName],\n };\n currentDatabase = database[configurationName];\n\n if (!trustedDomains[configurationName]) {\n trustedDomains[configurationName] = [];\n }\n }\n\n switch (data.type) {\n case 'clear':\n currentDatabase.tokens = null;\n currentDatabase.state = null;\n currentDatabase.codeVerifier = null;\n currentDatabase.status = data.data.status;\n port.postMessage({ configurationName });\n return;\n case 'init': {\n const oidcServerConfiguration = data.data.oidcServerConfiguration;\n const trustedDomain = trustedDomains[configurationName];\n const domains = getDomains(trustedDomain, 'oidc');\n if (!domains.find((f) => f === acceptAnyDomainToken)) {\n [\n oidcServerConfiguration.tokenEndpoint,\n oidcServerConfiguration.revocationEndpoint,\n oidcServerConfiguration.userInfoEndpoint,\n oidcServerConfiguration.issuer,\n ].forEach((url) => {\n checkDomain(domains, url);\n });\n }\n currentDatabase.oidcServerConfiguration = oidcServerConfiguration;\n currentDatabase.oidcConfiguration = data.data.oidcConfiguration;\n const where = data.data.where;\n if (\n where === 'loginCallbackAsync' ||\n where === 'tryKeepExistingSessionAsync'\n ) {\n currentLoginCallbackConfigurationName = configurationName;\n } else {\n currentLoginCallbackConfigurationName = null;\n }\n\n if (!currentDatabase.tokens) {\n port.postMessage({\n tokens: null,\n status: currentDatabase.status,\n configurationName,\n });\n } else {\n const tokens = {\n ...currentDatabase.tokens,\n };\n if (currentDatabase.hideAccessToken) {\n tokens.access_token = TOKEN.ACCESS_TOKEN + '_' + configurationName;\n }\n if (tokens.refresh_token) {\n tokens.refresh_token = TOKEN.REFRESH_TOKEN + '_' + configurationName;\n }\n if (\n tokens.idTokenPayload &&\n tokens.idTokenPayload.nonce &&\n currentDatabase.nonce != null\n ) {\n tokens.idTokenPayload.nonce =\n TOKEN.NONCE_TOKEN + '_' + configurationName;\n }\n port.postMessage({\n tokens,\n status: currentDatabase.status,\n configurationName,\n });\n }\n return;\n }\n case 'setState':\n currentDatabase.state = data.data.state;\n port.postMessage({ configurationName });\n return;\n case 'getState': {\n const state = currentDatabase.state;\n port.postMessage({ configurationName, state });\n return;\n }\n case 'setCodeVerifier':\n currentDatabase.codeVerifier = data.data.codeVerifier;\n port.postMessage({ configurationName });\n return;\n case 'getCodeVerifier': {\n port.postMessage({\n configurationName,\n codeVerifier: currentDatabase.codeVerifier != null ? TOKEN.CODE_VERIFIER + '_' + configurationName : null,\n });\n return;\n }\n case 'setSessionState':\n currentDatabase.sessionState = data.data.sessionState;\n port.postMessage({ configurationName });\n return;\n case 'getSessionState': {\n const sessionState = currentDatabase.sessionState;\n port.postMessage({ configurationName, sessionState });\n return;\n }\n case 'setNonce': {\n const nonce = data.data.nonce;\n if (nonce) {\n currentDatabase.nonce = nonce;\n }\n port.postMessage({ configurationName });\n return;\n }\n case 'getNonce': {\n const keyNonce = TOKEN.NONCE_TOKEN + '_' + configurationName;\n const nonce = currentDatabase.nonce ? keyNonce : null;\n port.postMessage({ configurationName, nonce });\n return;\n }\n default:\n currentDatabase.items = { ...data.data };\n port.postMessage({ configurationName });\n }\n};\n\n_self.addEventListener('install', handleInstall);\n_self.addEventListener('activate', handleActivate);\n_self.addEventListener('fetch', handleFetch);\n_self.addEventListener('message', handleMessage);\n"],"names":["domain","database","trustedDomains","response"],"mappings":"AAAA,MAAM,iBAAiB;AACvB,MAAM,uBAAuB;AAS7B,MAAM,QAAmB;AAAA,EACvB,eAAe;AA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AAK;AACxB,UAAI,OAAO;AACT,wBAAgB,QAAQ;AAAA,MAC1B;AACK,WAAA,YAAY,EAAE,kBAAA,CAAmB;AACtC;AAAA,IACF;AAAA,IACA,KAAK,YAAY;AACT,YAAA,WAAW,MAAM,cAAc,MAAM;AACrC,YAAA,QAAQ,gBAAgB,QAAQ,WAAW;AACjD,WAAK,YAAY,EAAE,mBAAmB,MAAO,CAAA;AAC7C;AAAA,IACF;AAAA,IACA;AACE,sBAAgB,QAAQ,EAAE,GAAG,KAAK,KAAK;AAClC,WAAA,YAAY,EAAE,kBAAA,CAAmB;AAAA,EAC1C;AACF;AAEA,MAAM,iBAAiB,WAAW,aAAa;AAC/C,MAAM,iBAAiB,YAAY,cAAc;AACjD,MAAM,iBAAiB,SAAS,WAAW;AAC3C,MAAM,iBAAiB,WAAW,aAAa;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Add bellow trusted domains, access tokens will automatically injected to be send to
|
|
2
|
+
// trusted domain can also be a path like https://www.myapi.com/users,
|
|
3
|
+
// then all subroute like https://www.myapi.com/useers/1 will be authorized to send access_token to.
|
|
4
|
+
|
|
5
|
+
// Domains used by OIDC server must be also declared here
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
const trustedDomains = {
|
|
8
|
+
default: ['https://demo.duendesoftware.com', 'https://kdhttps.auth0.com'],
|
|
9
|
+
config_classic: ['https://demo.duendesoftware.com'],
|
|
10
|
+
config_without_silent_login: ['https://demo.duendesoftware.com'],
|
|
11
|
+
config_without_refresh_token: ['https://demo.duendesoftware.com'],
|
|
12
|
+
config_without_refresh_token_silent_login: ['https://demo.duendesoftware.com'],
|
|
13
|
+
config_google: ['https://oauth2.googleapis.com', 'https://openidconnect.googleapis.com'],
|
|
14
|
+
config_with_hash: ['https://demo.duendesoftware.com'],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Service worker will continue to give access token to the JavaScript client
|
|
18
|
+
// Ideal to hide refresh token from client JavaScript, but to retrieve access_token for some
|
|
19
|
+
// scenarios which require it. For example, to send it via websocket connection.
|
|
20
|
+
trustedDomains.config_show_access_token = { domains: ['https://demo.duendesoftware.com'], showAccessToken: true };
|
|
21
|
+
|
|
22
|
+
// This example defines domains used by OIDC server separately from domains to which access tokens will be injected.
|
|
23
|
+
trustedDomains.config_separate_oidc_access_token_domains = {
|
|
24
|
+
oidcDomains: ['https://demo.duendesoftware.com'],
|
|
25
|
+
accessTokenDomains: ['https://myapi'],
|
|
26
|
+
};
|