Skip to content

Commit

Permalink
Merge pull request #2795 from Hyperkid123/sso-url-env-details-dynamic
Browse files Browse the repository at this point in the history
Add env based SSO url to getEnvDetails chrome method.
  • Loading branch information
BlakeHolifield authored Mar 20, 2024
2 parents 5c1b0ad + f6b507e commit 71cf36c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/auth/ChromeAuthContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createContext } from 'react';
import { OfflineTokenResponse } from './offline';

export type ChromeAuthContextValue<LoginResponse = void> = {
ssoUrl: string;
ready: boolean;
user: ChromeUser;
getUser: () => Promise<ChromeUser>;
Expand All @@ -30,6 +31,7 @@ const blankUser: ChromeUser = {
};

const ChromeAuthContext = createContext<ChromeAuthContextValue>({
ssoUrl: '',
ready: false,
logoutAllTabs: () => undefined,
loginAllTabs: () => undefined,
Expand Down
7 changes: 6 additions & 1 deletion src/auth/OIDCConnector/OIDCProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ const OIDCProvider: React.FC<React.PropsWithChildren> = ({ children }) => {

return (
<AuthProvider {...authProviderProps}>
<OIDCSecured cookieElement={cookieElement} setCookieElement={setCookieElement} microFrontendConfig={state.microFrontendConfig}>
<OIDCSecured
ssoUrl={state.ssoUrl}
cookieElement={cookieElement}
setCookieElement={setCookieElement}
microFrontendConfig={state.microFrontendConfig}
>
{children}
</OIDCSecured>
</AuthProvider>
Expand Down
4 changes: 3 additions & 1 deletion src/auth/OIDCConnector/OIDCSecured.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export function OIDCSecured({
microFrontendConfig,
cookieElement,
setCookieElement,
}: React.PropsWithChildren<{ microFrontendConfig: Record<string, any> } & FooterProps>) {
ssoUrl,
}: React.PropsWithChildren<{ microFrontendConfig: Record<string, any>; ssoUrl: string } & FooterProps>) {

Check warning on line 84 in src/auth/OIDCConnector/OIDCSecured.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 84 in src/auth/OIDCConnector/OIDCSecured.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const auth = useAuth();
const authRef = useRef(auth);
const store = useStore();
Expand All @@ -91,6 +92,7 @@ export function OIDCSecured({
const activeModule = useAtomValue(activeModuleDefinitionReadAtom);
const requiredScopes = activeModule?.config?.ssoScopes || [];
const [state, setState] = useState<ChromeAuthContextValue>({
ssoUrl,
ready: false,
logoutAllTabs: (bounce = true) => {
authChannel.postMessage({ type: 'logout' });
Expand Down
1 change: 1 addition & 0 deletions src/chrome/create-chrome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const mockUser: ChromeUser = {

describe('create chrome', () => {
const chromeAuthMock: ChromeAuthContextValue = {
ssoUrl: '',
doOffline() {
return Promise.resolve();
},
Expand Down
14 changes: 13 additions & 1 deletion src/chrome/create-chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,19 @@ export const createChromeContext = ({
getBundleData: useBundle,
getApp: () => getUrl('app'),
getEnvironment: () => getEnv(),
getEnvironmentDetails: () => getEnvDetails(),
getEnvironmentDetails: () => {
let environment = getEnvDetails();
if (environment && chromeAuth.ssoUrl) {
environment.sso = chromeAuth.ssoUrl;
} else {
environment = {
url: [],
portal: 'undefined',
sso: chromeAuth.ssoUrl,
};
}
return environment;
},
createCase: (fields?: any) => chromeAuth.getUser().then((user) => createSupportCase(user!.identity, chromeAuth.token, fields)),
getUserPermissions: async (app = '', bypassCache?: boolean) => {
const token = await chromeAuth.getToken();
Expand Down

0 comments on commit 71cf36c

Please sign in to comment.