-
Notifications
You must be signed in to change notification settings - Fork 19
/
appAuthServiceWorkerCore.js
42 lines (37 loc) · 1.42 KB
/
appAuthServiceWorkerCore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(function () {
"use strict";
var IdentityProxyServiceWorker = require("./IdentityProxyServiceWorker");
self.addEventListener("install", (event) => {
event.waitUntil(self.skipWaiting());
});
self.addEventListener("activate", (event) => {
event.waitUntil(self.clients.claim());
});
self.addEventListener("message", (event) => {
if (event.data.message === "configuration") {
self.identityProxy = new IdentityProxyServiceWorker(
event.data.resourceServers,
event.ports[0]
);
event.waitUntil(self.clients.claim().then(() =>
event.ports[0].postMessage({
"message": "configured"
})
));
} else if (event.data.message === "tokensRenewed") {
self.identityProxy.retryFailedRequests(event.data.resourceServer);
}
});
self.addEventListener("fetch", (event) => {
if (event.request.headers.get("x-appauthhelper-anonymous") === "true") {
return;
}
if (self.identityProxy) {
var resourceServer = self.identityProxy.getResourceServerFromUrl(event.request.url);
if (resourceServer && !event.request.headers.get("authorization")) {
event.respondWith(self.identityProxy.interceptRequest(event.request, resourceServer));
}
}
return;
});
}());