Skip to content

Commit 6ad76f7

Browse files
refactor
1 parent bc2f675 commit 6ad76f7

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ReactNode } from 'react';
22
import { 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

68
interface 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+
}

src/context/FrontendConfigContext.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ReactNode, createContext, use } from 'react';
22
import { DocLinkCreator } from '../lib/shared/links';
3-
import { OIDCConfig } from '../lib/oidc/onboardingApi';
43

54
export enum Landscape {
65
Live = 'LIVE',
@@ -10,6 +9,12 @@ export enum Landscape {
109
Local = 'LOCAL',
1110
}
1211

12+
export interface OIDCConfig {
13+
clientId: string;
14+
issuerUrl: string;
15+
scopes: string[];
16+
}
17+
1318
type FrontendConfig = {
1419
backendUrl: string;
1520
gatewayUrl: string;
@@ -18,11 +23,11 @@ type FrontendConfig = {
1823
oidcConfig: OIDCConfig;
1924
}
2025

21-
interface FrontendConfigContextProps extends FrontendConfig {
26+
interface FrontendConfigContextType extends FrontendConfig {
2227
links: DocLinkCreator;
2328
}
2429

25-
export const FrontendConfigContext = createContext<FrontendConfigContextProps | null>(
30+
export const FrontendConfigContext = createContext<FrontendConfigContextType | null>(
2631
null,
2732
);
2833

@@ -36,7 +41,7 @@ interface FrontendConfigProviderProps {
3641
export function FrontendConfigProvider({ children }: FrontendConfigProviderProps) {
3742
const config = use(fetchPromise);
3843
const docLinks = new DocLinkCreator(config.documentationBaseUrl);
39-
const value: FrontendConfigContextProps = {
44+
const value: FrontendConfigContextType = {
4045
links: docLinks,
4146
...config,
4247
};

src/lib/oidc/onboardingApi.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)