-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Use ServiceWorker for reactive authentication"
This reverts commit 3cd2818
- Loading branch information
Showing
6 changed files
with
41 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +0,0 @@ | ||
import {ReactiveAuthenticationClient} from "./scripts/ReactiveAuthenticationClient.js" | ||
import {UmaTokenProvider} from "./scripts/UmaTokenProvider.js" | ||
import {OidcTokenProvider} from "./packages/oidc/OidcTokenProvider.js" | ||
import {DPoPTokenProvider} from "./packages/oidc/DPoPTokenProvider.js" | ||
|
||
self.addEventListener("install", onInstall) | ||
self.addEventListener("activate", onActivate) | ||
self.addEventListener("fetch", onFetch) | ||
|
||
const session = new Map | ||
|
||
async function onInstall(e) { | ||
console.log("sw.onInstall", e) | ||
|
||
e.waitUntil(self.skipWaiting()) | ||
} | ||
|
||
async function onActivate(e) { | ||
console.log("sw.onActivate", e) | ||
await self.clients.claim() | ||
} | ||
|
||
function onFetch(e) { | ||
console.debug("sw.onFetch", e) | ||
|
||
if (!e.clientId) { | ||
console.debug("Ignore navigation") | ||
return | ||
} | ||
|
||
e.respondWith(fetchInternal(e)) | ||
} | ||
|
||
async function fetchInternal(e) { | ||
const client = await self.clients.get(e.clientId) | ||
|
||
const umaTokenProvider = new UmaTokenProvider(session) | ||
const dpopTokenProvider = new DPoPTokenProvider | ||
const oidcTokenProvider = new OidcTokenProvider | ||
|
||
umaTokenProvider.addEventListener("needCredentials", async e => e.detail.resolve(await postAndWaitForResponse(client, "needCredentials"))) | ||
dpopTokenProvider.addEventListener("needCredentials", async e => e.detail.resolve(await postAndWaitForResponse(client, "needCredentials"))) | ||
oidcTokenProvider.addEventListener("needCredentials", async e => e.detail.resolve(await postAndWaitForResponse(client, "needCredentials"))) | ||
|
||
const rac = new ReactiveAuthenticationClient(session, [umaTokenProvider, dpopTokenProvider, oidcTokenProvider], self.fetch) | ||
return await rac.fetch(e.request) | ||
} | ||
|
||
async function postAndWaitForResponse(target, message) { | ||
const channel = new MessageChannel() | ||
|
||
try { | ||
return await new Promise(resolve => { | ||
channel.port1.onmessage = e => resolve(e.data) | ||
|
||
target.postMessage(message, [channel.port2]) | ||
}) | ||
|
||
} finally { | ||
channel.port1.onmessage = undefined | ||
} | ||
} | ||