Gathering detailed insights and metrics for @axa-fr/vanilla-oidc
Gathering detailed insights and metrics for @axa-fr/vanilla-oidc
Gathering detailed insights and metrics for @axa-fr/vanilla-oidc
Gathering detailed insights and metrics for @axa-fr/vanilla-oidc
Light, Secure, Pure Javascript OIDC (Open ID Connect) Client. We provide also a REACT wrapper (compatible NextJS, etc.).
npm install @axa-fr/vanilla-oidc
Typescript
Module System
Node Version
NPM Version
TypeScript (94.27%)
JavaScript (5.23%)
Shell (0.49%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
653 Stars
1,278 Commits
166 Forks
21 Watchers
73 Branches
56 Contributors
Updated on Jul 04, 2025
Latest Version
6.25.6
Package Id
@axa-fr/vanilla-oidc@6.25.6
Unpacked Size
267.78 kB
Size
64.30 kB
File Count
82
NPM Version
9.5.1
Node Version
18.16.1
Published on
Jul 24, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
18
Try the demo at https://icy-glacier-004ab4303.2.azurestaticapps.net/
@axa-fr/vanilla-oidc is a pure OIDC client library agnostic to any framework. It is used by @axa-fr/react-oidc and can be used by any framework.
It is a real alternative to existing oidc-client libraries.
OidcTrustedDomains.js
fileThe service worker catch access_token and refresh_token that will never be accessible to the client.
1npm install @axa-fr/vanilla-oidc --save 2 3# If you have a "public" folder, the 2 files will be created : 4# ./public/OidcServiceWorker.js <-- will be updated at each "npm install" 5# ./public/OidcTrustedDomains.js <-- won't be updated if already exist
If you need a very secure mode where refresh_token and access_token will be hide behind a service worker that will proxify requests. The only file you should edit is "OidcTrustedDomains.js".
1// OidcTrustedDomains.js 2 3// Add bellow trusted domains, access tokens will automatically injected to be send to 4// trusted domain can also be a path like https://www.myapi.com/users, 5// then all subroute like https://www.myapi.com/useers/1 will be authorized to send access_token to. 6 7// Domains used by OIDC server must be also declared here 8const trustedDomains = { 9 default: ["https://demo.duendesoftware.com", "https://www.myapi.com/users"], 10};
The code of the demo :
1import { VanillaOidc } from '@axa-fr/vanilla-oidc' 2 3export const configuration = { 4 client_id: 'interactive.public.short', 5 redirect_uri: window.location.origin + '/#/authentication/callback', 6 silent_redirect_uri: window.location.origin + '/#/authentication/silent-callback', 7 scope: 'openid profile email api offline_access', 8 authority: 'https://demo.duendesoftware.com', 9 service_worker_relative_url:'/OidcServiceWorker.js', 10 service_worker_only: false, 11}; 12 13const href = window.location.href; 14const vanillaOidc = VanillaOidc.getOrCreate(() => fetch)(configuration); 15 16console.log(href); 17 18vanillaOidc.tryKeepExistingSessionAsync().then(() => { 19 if(href.includes(configuration.redirect_uri)){ 20 vanillaOidc.loginCallbackAsync().then(()=>{ 21 window.location.href = "/"; 22 }); 23 document.body.innerHTML = `<div> 24 <h1>@axa-fr/vanilla-oidc demo</h1> 25 <h2>Loading</h2> 26 </div>`; 27 return 28 } 29 30 let tokens = vanillaOidc.tokens; 31 32 if(tokens){ 33 34 // @ts-ignore 35 window.logout = () => vanillaOidc.logoutAsync(); 36 document.body.innerHTML = `<div> 37 <h1>@axa-fr/vanilla-oidc demo</h1> 38 <button onclick="window.logout()">Logout</button> 39 <h2>Authenticated</h2> 40 <pre>${JSON.stringify(tokens,null,'\t')}</pre> 41 </div>` 42 43 } 44 else { 45 // @ts-ignore 46 window.login= () => vanillaOidc.loginAsync("/"); 47 document.body.innerHTML = `<div> 48 <h1>@axa-fr/vanilla-oidc demo</h1> 49 <button onclick="window.login()">Login</button> 50 </div>` 51 } 52}) 53 54
1const configuration: { 2 client_id: PropTypes.string.isRequired, // oidc client id 3 redirect_uri: PropTypes.string.isRequired, // oidc redirect url 4 silent_redirect_uri: PropTypes.string, // Optional activate silent-signin that use cookies between OIDC server and client javascript to restore sessions 5 silent_login_uri: PropTypes.string, // Optional, route that trigger the signin 6 silent_login_timeout: PropTypes.number, // Optional default is 12000 milliseconds 7 scope: PropTypes.string.isRequired, // oidc scope (you need to set "offline_access") 8 authority: PropTypes.string.isRequired, 9 storage: Storage, // Default sessionStorage, you can set localStorage but it is less secure to XSS attacks 10 authority_configuration: PropTypes.shape({ 11 // Optional for providers that does not implement OIDC server auto discovery via a .wellknowurl 12 authorization_endpoint: PropTypes.string, 13 token_endpoint: PropTypes.string, 14 userinfo_endpoint: PropTypes.string, 15 end_session_endpoint: PropTypes.string, 16 revocation_endpoint: PropTypes.string, 17 check_session_iframe: PropTypes.string, 18 issuer: PropTypes.string, 19 }), 20 refresh_time_before_tokens_expiration_in_second: PropTypes.number, // default is 120 seconds 21 service_worker_relative_url: PropTypes.string, 22 service_worker_only: PropTypes.boolean, // default false 23 service_worker_convert_all_requests_to_cors: PropTypes.boolean, // force all requests that servie worker upgrades to have 'cors' mode. This allows setting authentication token on requests initialted by html parsing(e.g. img tags, download links etc). 24 extras: StringMap | undefined, // ex: {'prompt': 'consent', 'access_type': 'offline'} list of key/value that are send to the oidc server (more info: https://github.com/openid/AppAuth-JS) 25 token_request_extras: StringMap | undefined, // ex: {'prompt': 'consent', 'access_type': 'offline'} list of key/value that are send to the oidc server during token request (more info: https://github.com/openid/AppAuth-JS) 26 withCustomHistory: PropTypes.function, // Override history modification, return instance with replaceState(url, stateHistory) implemented (like History.replaceState()) 27 authority_time_cache_wellknowurl_in_second: 60 * 60, // Time to cache in second of openid wellknowurl, default is 1 hour 28 authority_timeout_wellknowurl_in_millisecond: 10000, // Timeout in millisecond of openid wellknowurl, default is 10 seconds, then error is throwed 29 monitor_session: PropTypes.boolean, // Add OpenId monitor session, default is false (more information https://openid.net/specs/openid-connect-session-1_0.html), if you need to set it to true consider https://infi.nl/nieuws/spa-necromancy/ 30 onLogoutFromAnotherTab: Function, // Optional, can be set to override the default behavior, this function is triggered when user with the same subject is logged out from another tab when session_monitor is active 31 onLogoutFromSameTab: Function, // Optional, can be set to override the default behavior, this function is triggered when user is logged out from same tab when session_monitor is active 32 token_renew_mode: PropTypes.string, // Optional, update tokens base on the selected token(s) lifetime: "access_token_or_id_token_invalid" (default), "access_token_invalid" , "id_token_invalid" 33 logout_tokens_to_invalidate : Array<string> // Optional tokens to invalidate during logout, default: ['access_token', 'refresh_token'] 34 };
1git clone https://github.com/AxaGuilDEv/react-oidc.git 2cd react-oidc/packages/vanilla-demo 3npm install 4npm start 5# then navigate to http://localhost:3000
This component is a pure vanilla JS OIDC client library agnostic to any framework. It is a real alternative to existing oidc-client libraries.
More information about OIDC
vanilla-oidc
work also with hash route.
1export const configurationIdentityServerWithHash = { 2 client_id: "interactive.public.short", 3 redirect_uri: window.location.origin + "#authentication-callback", 4 silent_redirect_uri: 5 window.location.origin + "#authentication-silent-callback", 6 scope: "openid profile email api offline_access", 7 authority: "https://demo.duendesoftware.com", 8 refresh_time_before_tokens_expiration_in_second: 70, 9 service_worker_relative_url: "/OidcServiceWorker.js", 10 service_worker_only: false, 11};
No vulnerabilities found.
No security vulnerabilities found.