CodeCoupler Application Basics Combine service-worker and oidc 🔒
If you want to combine the Service Worker Loader with your own service worker and the OIDC Authentication Library, you just need to load your own service worker and import the OIDC service worker:
Preparations
After that, a few things need to be taken into account:
(1) If you are using oidc-client version 7.24 or below you must remove its event
listeners install and activate:
(2) Your own service worker has to listen to the message that'll trigger
self.skipWaiting(). Here an example listening to the message
{ codecoupler: "cc-skip-message" }:
(3) Important: Do not use self.addEventListener("fetch", (e) => {}) in
your own service worker. Or ensure at least you do not call respondWith()
inside of your listener when the authentication or the resource server is
requested.
Usage
Then you can load your own service worker with this configuration:
You have to pay attention whenever you send a message to your own service worker
you've got to add the property configurationName to the message data object.
Instead of:
You have to post:
This is because the event handler of the OIDC library will also catch these
messages. If there isn't a configuration name (which is specified in
OidcTrustedDomains.js), it'll run into an exception.