
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@axa-fr/auth-worker
Advanced tools
Auth-worker provides a service worker to easily manage Oidc authentication.
Auth-worker provides a service worker to easily manage Oidc authentication.
After the setup and depending on the fetch request, the token will be automatically added in the header.

:warning: Not on npm right now...
npm install @axa-fr/auth-worker
The usage is quite simple. Two methods are needed :
A 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.
The start method takes two parameters : the oidc configuration and the optionnal worker configuration.
The 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 :
const map = new Map();
map.set(['https://my.app/api'], {
openIdConnectProvider: 'https://accounts.google.com',
clientId: '123456789',
callbackRedirectUri: 'https://my.app/callback',
scope: 'scope',
});
await start(map, {
swPath: '/oidcsw.js',
customUI: {
callbackComponent: '',
loadingComponent: '',
},
});
The 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.
The callback method have to be called on the page targeted by callbackRedirectUri parameter
callback();
You can look at the /dev folder for a simple usecase.
This is an example for an usage in a React project
App.js
import { useState, useEffect } from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { UserContext, useUser } from 'services/user';
import { conf } from 'services/environments';
import { start } from 'auth-worker';
import AuthenticationCallback from 'pages/AuthenticationCallback';
import AppContent from './AppContent';
const App = () => {
const [isLogged, setIsLogged] = useState(false);
const valueUseUser = useUser();
useEffect(async () => {
(async () => {
const map = new Map();
map.set([conf.apiUrl, conf.referentielMachineUrl], {
openIdConnectProvider: conf.oidc.openIdConnectProvider,
clientId: conf.oidc.clientId,
callbackRedirectUri: conf.oidc.callbackRedirectUri,
scope: conf.oidc.scope,
});
await start(map, {
swPath: '/oidcsw.js',
customUI: {
callbackComponent: '',
loadingComponent: '',
},
});
setIsLogged(true);
})();
}, []);
return (
<Router>
<Route
component={AuthenticationCallback}
exact
path={`${conf.baseUrl}/${conf.oidc.callbackUrl}`}
/>
{isLogged ? (
<UserContext.Provider value={valueUseUser}>
<AppContent />
</UserContext.Provider>
) : null}
</Router>
);
};
export default App;
You can retrieve the user informations in the AppContent for example, this information can be stored in the contexte provided by the UserContext.
pages/AuthenticationCallback.js
import { useEffect } from 'react';
import { callback } from 'auth-worker';
const AuthenticationCallback = () => {
useEffect(() => {
callback();
}, []);
return <h1>Callback</h1>;
};
export default AuthenticationCallback;
Before you start working on something, it's best to check if there is an existing issue first.
Please make sure to read the Contributing Guide before making a pull request.
Thank you to everyone contributing!
FAQs
Auth-worker provides a service worker to easily manage Oidc authentication.
We found that @axa-fr/auth-worker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.