{"id":28580350,"url":"https://github.com/axafrance/auth-worker","last_synced_at":"2025-10-12T13:05:06.914Z","repository":{"id":37085609,"uuid":"493707715","full_name":"AxaFrance/auth-worker","owner":"AxaFrance","description":"Make Oidc authentication easy with a cross-framework / service worker solution","archived":false,"fork":false,"pushed_at":"2022-10-26T14:53:35.000Z","size":1151,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-06-11T03:44:23.338Z","etag":null,"topics":["axa","oidc","security","service-worker","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AxaFrance.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-18T14:52:59.000Z","updated_at":"2024-10-23T11:41:44.000Z","dependencies_parsed_at":"2023-01-19T10:22:40.621Z","dependency_job_id":null,"html_url":"https://github.com/AxaFrance/auth-worker","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/AxaFrance/auth-worker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxaFrance%2Fauth-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxaFrance%2Fauth-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxaFrance%2Fauth-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxaFrance%2Fauth-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AxaFrance","download_url":"https://codeload.github.com/AxaFrance/auth-worker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxaFrance%2Fauth-worker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011468,"owners_count":26084947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axa","oidc","security","service-worker","typescript"],"created_at":"2025-06-11T03:40:04.127Z","updated_at":"2025-10-12T13:05:06.908Z","avatar_url":"https://github.com/AxaFrance.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"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\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./demo.gif\"\n     alt=\"Sample React Oicd\"\n      /\u003e\n\u003c/p\u003e\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 = () =\u003e {\n    const [isLogged, setIsLogged] = useState(false);\n    const valueUseUser = useUser();\n\n    useEffect(async () =\u003e {\n        (async () =\u003e {\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        \u003cRouter\u003e\n            \u003cRoute\n                component={AuthenticationCallback}\n                exact\n                path={`${conf.baseUrl}/${conf.oidc.callbackUrl}`}\n            /\u003e\n            {isLogged ? (\n                \u003cUserContext.Provider value={valueUseUser}\u003e\n                    \u003cAppContent /\u003e\n                \u003c/UserContext.Provider\u003e\n            ) : null}\n        \u003c/Router\u003e\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 = () =\u003e {\n    useEffect(() =\u003e {\n        callback();\n    }, []);\n\n    return \u003ch1\u003eCallback\u003c/h1\u003e;\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxafrance%2Fauth-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxafrance%2Fauth-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxafrance%2Fauth-worker/lists"}