11import { ReactNode } from 'react' ;
22import { AuthProvider } from 'react-oidc-context' ;
3- import { useFrontendConfig } from './FrontendConfigContext.tsx' ;
4- import { buildAuthProviderProps } from '../lib/oidc/onboardingApi.ts' ;
3+ import { OIDCConfig , useFrontendConfig } from './FrontendConfigContext.tsx' ;
4+ import { WebStorageStateStore } from "oidc-client-ts" ;
5+ import { AuthProviderProps } from "react-oidc-context" ;
6+
57
68interface AuthProviderOnboardingProps {
79 children ?: ReactNode ;
@@ -12,6 +14,23 @@ export function AuthProviderOnboarding({
1214} : AuthProviderOnboardingProps ) {
1315 const { oidcConfig } = useFrontendConfig ( ) ;
1416
15- const authConfig = buildAuthProviderProps ( oidcConfig ) ;
17+ const authConfig = buildAuthProviderConfig ( oidcConfig ) ;
1618 return < AuthProvider { ...authConfig } > { children } </ AuthProvider > ;
1719}
20+
21+ export function buildAuthProviderConfig ( oidcConfig : OIDCConfig ) {
22+ const userStore = new WebStorageStateStore ( { store : window . localStorage } ) ;
23+
24+ const props : AuthProviderProps = {
25+ authority : oidcConfig . issuerUrl ,
26+ client_id : oidcConfig . clientId ,
27+ redirect_uri : window . location . origin ,
28+ scope : oidcConfig . scopes . join ( ' ' ) ,
29+ userStore : userStore ,
30+ automaticSilentRenew : false , // we show a window instead that asks the user to renew the token
31+ onSigninCallback : ( ) => {
32+ window . history . replaceState ( { } , document . title , window . location . pathname ) ;
33+ } ,
34+ } ;
35+ return props ;
36+ }
0 commit comments