{"_id":"@axa-fr/auth-worker","_rev":"9-26b16037bbcfc246bfbee76644521c84","name":"@axa-fr/auth-worker","dist-tags":{"latest":"1.0.1","beta":"1.0.2"},"versions":{"1.0.1":{"name":"@axa-fr/auth-worker","version":"1.0.1","keywords":[],"author":"","license":"MIT","_id":"@axa-fr/auth-worker@1.0.1","maintainers":[{"name":"fcornaire","email":"darkshad66@gmail.com"},{"name":"guillaume.chervet.axa","email":"guillaume.chervet@axa.fr"},{"name":"samuel-gomez","email":"samuel.gomez@axa.fr"},{"name":"antoine.blancke","email":"antoine.blancke@axa.fr"},{"name":"arnaudforaison","email":"arnaud.foraison@gmail.com"}],"bin":{"init":"bin/init.js"},"dist":{"shasum":"039bc2d5063d22c12974e33bcacf44d66a5f4738","tarball":"https://registry.npmjs.org/@axa-fr/auth-worker/-/auth-worker-1.0.1.tgz","fileCount":32,"integrity":"sha512-eA+R3UwhrkeZru73lj4UEAqzH7D2kUsPCoNjJtnI1fTeZZlVf1gs6AD3k4NTIS5HQuLJbqeE7f+BbYjDoe2G2A==","signatures":[{"sig":"MEYCIQCLzfZccJ6t9Uj1EkQkdEH7/ozMebZfH21kVZ5Kz/D1YgIhALUBHext77NxlQhMzuxKol1uzPovTNiB5XJiBPiDi81N","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":775816,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJisYtJACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoBKw//T2Ru9O/8b77QVdULXa6rM8KZMoFuZ/cjTUa2P81zd1D4wwvr\r\nc6ksmjXYulyM9nhrpfy+1WhnRwXWac1GMxfmbtuucUyRmuir/k4TgfJMwETX\r\n57okiDQTKguOJ0kfoZ3dfVuZi7JBuDd3WHP8vFBeyY5dKkrNAEikoohyrDsC\r\nh5lAZeo8zvg3rQdwtadQYsl88eEqCaIANBR1QZzXEKW58L/xADEPblOwvbo8\r\n6F5kQgUHtMk/MWwCp6HHp7S+xy49WdECl/pzEAG0lOZEnU3Sp7fi3yfTIuuI\r\nExWWJKojxVJkL46zU/MDLdPI21RRTZG5swD/fUYH/Xc8XcL7EGi5mm6UaH9W\r\n2xP9cWmB6oj+K/0zXmaLXLzWgDGPkInGnj+3RoQAmSKopk6s2qFxxSQE8Two\r\naiMCbXWH7GWvgeD48WrQVE4u6Ro4VzRFF78ngZCL0s+3zX+zbQbLaB1tQYFK\r\nFmVgA51NKSD4Vh+iiJrEqxMIF48T4iMJ0jgAZX1CiUbVEP+TRou71NskeGhT\r\nYy0K10xT2fw954iYVKAC9X3tpfCs/AZwp0q4CKzCkeEsZ06DSBXu3p53fpgw\r\nR5EcqE4fCRHx8GZLDycT+kG801wDgDApW1JHzdzSGP/UTHTq7TqCglfsRCOZ\r\n8l7OnIWlg6YMF4rCwYkvrmeEbRN4UcyKMqE=\r\n=dzlo\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/main/main.umd.js","types":"dist/types/main/index.d.ts","module":"./dist/main/main.es.js","exports":{".":{"import":"./dist/main/main.es.js","require":"./dist/main/main.es.js"}},"gitHead":"f85b96ed3d1a0b3b031174059274ec063cdc3a69","scripts":{"build":"tsc --declaration --emitDeclarationOnly --outDir ./dist/types && concurrently \"vite build -c conf/vite.config.js\" \"vite build -c conf/vite.sw.config.js\"","serve":"vite preview","start":"concurrently \"yarn run build:dev\"  \"vite serve dev\"","eslint":"eslint --fix","prepare":"husky install","release":"standard-version","build:dev":"concurrently \"vite build -c conf/vite.config.dev.js --watch\" \"vite build -c conf/vite.sw.config.dev.js\" --watch","postinstall":"node bin/init.js copy","pretty-quick":"pretty-quick --staged"},"_npmUser":{"name":"fcornaire","email":"darkshad66@gmail.com"},"_npmVersion":"8.11.0","description":"Auth-worker provides a service worker to easily manage Oidc authentication.","directories":{},"sideEffects":["dist/main/main.umd.js"],"_nodeVersion":"16.15.1","dependencies":{"chalk":"^4.1.2","yargs":"^17.1.0","localforage":"^1.9.0","@openid/appauth":"^1.3.1"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^2.6.4","husky":"^7.0.0","eslint":"^7.32.0","prettier":"^2.3.2","cross-env":"^7.0.3","typescript":"^4.3.2","concurrently":"^6.3.0","pretty-quick":"^3.1.1","@commitlint/cli":"^15.0.0","standard-version":"^9.3.2","@commitlint/config-conventional":"^15.0.0"},"standard-version":{"skip":{"commit":true}},"_npmOperationalInternal":{"tmp":"tmp/auth-worker_1.0.1_1655802697045_0.8696150482070637","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"@axa-fr/auth-worker","version":"1.0.2","keywords":[],"author":"","license":"MIT","_id":"@axa-fr/auth-worker@1.0.2","maintainers":[{"name":"fcornaire","email":"darkshad66@gmail.com"},{"name":"guillaume.chervet.axa","email":"guillaume.chervet@axa.fr"},{"name":"samuel-gomez","email":"samuel.gomez@axa.fr"},{"name":"antoine.blancke","email":"antoine.blancke@axa.fr"},{"name":"arnaudforaison","email":"arnaud.foraison@gmail.com"}],"bin":{"init":"bin/init.js"},"dist":{"shasum":"fd881b27d5ec031592f22777ecf6ff6086bc9d74","tarball":"https://registry.npmjs.org/@axa-fr/auth-worker/-/auth-worker-1.0.2.tgz","fileCount":32,"integrity":"sha512-VuyVY1V/9rBn802M7CBDVwyfQNnXvOpClPYZJp/h8kzaOcCPuXJuTpZY1KKgeXgJKCEpelpGUcjjdmh51/kmxg==","signatures":[{"sig":"MEYCIQCX0hrKW9raxVh78YvK0IEzmvPL1eHCUMPcnSYQ0/AehQIhAPQsLFETjNfqtPvaSLInLR/297qg97ab3FoATa7J6WK7","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":775930,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjWUrsACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoPjQ//dxNEAZFxYxcfGierX5qllAns8XW4W9H0/AZh9N6UflalcJ2E\r\nPlvgDZaC8pRjzPFQO9euOeUp1L0FVaGmxPaFySNawWSGVclPIAvyFonpJ/5L\r\nck5PIEYjgttUmzVQC3e64albN9Xg0egxQWpOknenGMDLxRn1HslB6TxK1y94\r\nSl5jTNg5YYTGtPHosV5asHZS9+ZRZZhQLaQ24Ac9Y+RkIgVKdH5KP+dcjD4n\r\nSRI6B0iR9Qwz4G/cKKjGWCjBMGQBgJDDp8gUr2rs7hmXMVc1cFuJSEUQY9vO\r\nWXHiv50Yx9LEHsWU7T0lu3URUNgVujeYCsFCtesVD2YNDOEMKfV7XZFlvRXW\r\ntncc2NRm4VLZpPDIDZqLGQmFV88wyi3ktsac0v93fKa9QuYXLpV054wH5d6V\r\nqatxBCUhl2anKaAnsApP+AJXjLDX8vtAEPSLoUCRnmg2EPbQZXjxT/UCdIe4\r\nyA876NGVzx5J//tdLShlEBiZBh4vLeyTPehQ4CEp8K39wYGZQcTWAxq4nTfw\r\nw5SksvPa1BOnQz/VRCJwl5vgph7vzgTF7bJ5IRaAS0Q9Fs3FJUasCSa3ellK\r\nKxqUn0MSx24IWwBWt3OjWyyQf0Vxj9eNad8BUjTsL/tvh4uWSAkGLYY1VXTr\r\nJxZUmjqF0pfNs52BrD2tI5cVKs/jOSPwKI4=\r\n=GzkV\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/main/main.umd.js","types":"dist/types/main/index.d.ts","module":"./dist/main/main.es.js","readme":"# Auth-worker\n\nAuth-worker provides a service worker to easily manage Oidc authentication.\n\nAfter the setup and depending on the fetch request, the token will be automatically added in the header.\n\n<p align=\"center\">\n    <img src=\"./demo.gif\"\n     alt=\"Sample React Oicd\"\n      />\n</p>\n\n![workflow](AuthWorkerFlow.png 'AuthWorker Flow')\n\n## Prerequisite\n\n-   Identity Provider\n-   Client ID\n-   Scope\n\n## Usage\n\n:warning: Not on npm right now...\n\n```npm\nnpm install @axa-fr/auth-worker\n```\n\nThe usage is quite simple. Two methods are needed :\n\n-   start\n-   callback\n\nA file containing the service worker is copied in your `public` folder during the `npm install`. If it fails, you can use `npx auth-worker init ${path}` to build and copy the worker where you want.\n\n### Start\n\nThe `start` method takes two parameters : the oidc configuration and the optionnal worker configuration.\n\nThe oidc configuration is based on a javascript map. The key is the list of all the domain that have to be intercepted by the worker, the value is the oidc configuration :\n\n-   openIdConnectProvider\n-   clientId\n-   callbackRedirectUri\n-   scope\n\n```javascript\nconst map = new Map();\nmap.set(['https://my.app/api'], {\n    openIdConnectProvider: 'https://accounts.google.com',\n    clientId: '123456789',\n    callbackRedirectUri: 'https://my.app/callback',\n    scope: 'scope',\n});\nawait start(map, {\n    swPath: '/oidcsw.js',\n    customUI: {\n        callbackComponent: '',\n        loadingComponent: '',\n    },\n});\n```\n\nThe worker configuration is optional. You can override some parameters like the path of the worker, and the webcomponent that have to be display during the logging process.\n\n### Callback\n\nThe `callback` method have to be called on the page targeted by callbackRedirectUri parameter\n\n```javascript\ncallback();\n```\n\n## Implementation\n\nYou can look at the `/dev` folder for a simple usecase.\n\n### React\n\nThis is an example for an usage in a React project\n\n**_App.js_**\n\n```javascript\nimport { useState, useEffect } from 'react';\nimport { BrowserRouter as Router, Route } from 'react-router-dom';\nimport { UserContext, useUser } from 'services/user';\nimport { conf } from 'services/environments';\nimport { start } from 'auth-worker';\nimport AuthenticationCallback from 'pages/AuthenticationCallback';\n\nimport AppContent from './AppContent';\n\nconst App = () => {\n    const [isLogged, setIsLogged] = useState(false);\n    const valueUseUser = useUser();\n\n    useEffect(async () => {\n        (async () => {\n            const map = new Map();\n            map.set([conf.apiUrl, conf.referentielMachineUrl], {\n                openIdConnectProvider: conf.oidc.openIdConnectProvider,\n                clientId: conf.oidc.clientId,\n                callbackRedirectUri: conf.oidc.callbackRedirectUri,\n                scope: conf.oidc.scope,\n            });\n            await start(map, {\n                swPath: '/oidcsw.js',\n                customUI: {\n                    callbackComponent: '',\n                    loadingComponent: '',\n                },\n            });\n\n            setIsLogged(true);\n        })();\n    }, []);\n\n    return (\n        <Router>\n            <Route\n                component={AuthenticationCallback}\n                exact\n                path={`${conf.baseUrl}/${conf.oidc.callbackUrl}`}\n            />\n            {isLogged ? (\n                <UserContext.Provider value={valueUseUser}>\n                    <AppContent />\n                </UserContext.Provider>\n            ) : null}\n        </Router>\n    );\n};\n\nexport default App;\n```\n\nYou can retrieve the user informations in the `AppContent` for example, this information can be stored in the contexte provided by the `UserContext`.\n\n**_pages/AuthenticationCallback.js_**\n\n```javascript\nimport { useEffect } from 'react';\nimport { callback } from 'auth-worker';\n\nconst AuthenticationCallback = () => {\n    useEffect(() => {\n        callback();\n    }, []);\n\n    return <h1>Callback</h1>;\n};\n\nexport default AuthenticationCallback;\n```\n\n### TODO\n\n-   [ ] Easier setup for start (No map parameter on entry)\n-   [ ] Support for custom (non oidc) provider\n-   [ ] Add popular framework wrapper\n-   [ ] Safari support ( dropping Broadcast Channel )\n\n### Contributing\n\nBefore you start working on something, it's best to check if there is an existing issue first.\n\nPlease make sure to read the [Contributing Guide](./.github/CONTRIBUTING.md) before making a pull request.\n\nThank you to everyone contributing!\n","exports":{".":{"import":"./dist/main/main.es.js","require":"./dist/main/main.es.js"}},"gitHead":"da4ecb6181edb93e17f9fdc21759f1482534c130","scripts":{"build":"tsc --declaration --emitDeclarationOnly --outDir ./dist/types && concurrently \"vite build -c conf/vite.config.js\" \"vite build -c conf/vite.sw.config.js\"","serve":"vite preview","start":"concurrently \"yarn run build:dev\"  \"vite serve dev\"","eslint":"eslint --fix","prepare":"husky install","release":"standard-version","build:dev":"concurrently \"vite build -c conf/vite.config.dev.js --watch\" \"vite build -c conf/vite.sw.config.dev.js\" --watch","postinstall":"node bin/init.js copy","pretty-quick":"pretty-quick --staged"},"_npmUser":{"name":"fcornaire","email":"darkshad66@gmail.com"},"_npmVersion":"8.15.0","description":"Auth-worker provides a service worker to easily manage Oidc authentication.","directories":{},"sideEffects":["dist/main/main.umd.js"],"_nodeVersion":"16.17.1","dependencies":{"chalk":"^4.1.2","yargs":"^17.1.0","localforage":"^1.9.0","@openid/appauth":"^1.3.1"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"vite":"^2.9.13","husky":"^7.0.0","eslint":"^7.32.0","prettier":"^2.3.2","cross-env":"^7.0.3","typescript":"^4.3.2","concurrently":"^6.3.0","pretty-quick":"^3.1.1","@commitlint/cli":"^15.0.0","standard-version":"^9.3.2","@commitlint/config-conventional":"^15.0.0"},"standard-version":{"skip":{"commit":true}},"_npmOperationalInternal":{"tmp":"tmp/auth-worker_1.0.2_1666796268730_0.2940878045525548","host":"s3://npm-registry-packages"}}},"time":{"created":"2022-06-21T09:11:36.997Z","modified":"2025-12-08T13:49:16.777Z","1.0.0":"2022-06-17T14:50:39.629Z","1.0.1":"2022-06-21T09:11:37.298Z","1.0.2":"2022-10-26T14:57:48.962Z"},"license":"MIT","keywords":[],"description":"Auth-worker provides a service worker to easily manage Oidc authentication.","maintainers":[{"email":"guillaume.chervet@axa.fr","name":"guillaume.chervet.axa"},{"email":"samuel.gomez@axa.fr","name":"samuel-gomez"},{"email":"arnaud.foraison@gmail.com","name":"arnaudforaison"},{"email":"johnathan2693@gmail.com","name":"johnathan.meunier"},{"email":"stievenart.m@gmail.com","name":"martinweb"}],"readme":"","readmeFilename":""}