Skip to content

Commit

Permalink
feat: add sso config to sso info panel
Browse files Browse the repository at this point in the history
  • Loading branch information
mistahj67 committed Dec 2, 2024
1 parent 97cbb94 commit b21b974
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/javascript/bh-shared-ui/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default {
'notistack',
'react-query',
'js-client-library',
'js-file-download',
'swagger-ui-react',
'swagger-ui-react/swagger-ui.css',
'prop-types',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
// SPDX-License-Identifier: Apache-2.0

import { Paper, Box, Typography, useTheme } from '@mui/material';
import { FC } from 'react';
import { FC, useMemo } from 'react';
import fileDownload from 'js-file-download';
import { OIDCProviderInfo, SAMLProviderInfo, SSOProvider } from 'js-client-library';
import { Button } from '@bloodhoundenterprise/doodleui';
import { OIDCProviderInfo, SAMLProviderInfo, SSOProvider, Role } from 'js-client-library';
import { Button, Label } from '@bloodhoundenterprise/doodleui';
import { Field, FieldsContainer, usePaneStyles, useHeaderStyles } from '../../views/Explore';
import LabelWithCopy from '../LabelWithCopy';
import { apiClient } from '../../utils';
Expand All @@ -27,7 +27,7 @@ import { useNotifications } from '../../providers';
const SAMLProviderInfoPanel: FC<{
samlProviderDetails: SAMLProviderInfo;
}> = ({ samlProviderDetails }) => (
<FieldsContainer>
<>
<Field
label={<LabelWithCopy label='IdP SSO URL' valueToCopy={samlProviderDetails.idp_sso_uri} hoverOnly />}
value={samlProviderDetails.idp_sso_uri}
Expand All @@ -46,15 +46,15 @@ const SAMLProviderInfoPanel: FC<{
}
value={samlProviderDetails.sp_metadata_uri}
/>
</FieldsContainer>
</>
);

const OIDCProviderInfoPanel: FC<{
ssoProvider: SSOProvider;
}> = ({ ssoProvider }) => {
const oidcProviderDetails = ssoProvider.details as OIDCProviderInfo;
return (
<FieldsContainer>
<>
<Field
label={<LabelWithCopy label='Client ID' valueToCopy={oidcProviderDetails.client_id} hoverOnly />}
value={oidcProviderDetails.client_id}
Expand All @@ -67,32 +67,38 @@ const OIDCProviderInfoPanel: FC<{
label={<LabelWithCopy label='Callback URL' valueToCopy={ssoProvider.callback_uri} hoverOnly />}
value={ssoProvider.callback_uri}
/>
</FieldsContainer>
</>
);
};

const SSOProviderInfoPanel: FC<{
ssoProvider: SSOProvider;
}> = ({ ssoProvider }) => {
roles?: Role[];
}> = ({ ssoProvider, roles }) => {
const theme = useTheme();
const paneStyles = usePaneStyles();
const headerStyles = useHeaderStyles();
const { addNotification } = useNotifications();

const defaultRoleName = useMemo(
() => roles?.find((role) => role.id === ssoProvider.config?.auto_provision?.default_role)?.name,
[roles, ssoProvider.config?.auto_provision?.default_role]
);

if (!ssoProvider.type) {
return null;
}

let infoPanel;
let innerInfoPanel;
switch (ssoProvider.type.toLowerCase()) {
case 'saml':
infoPanel = <SAMLProviderInfoPanel samlProviderDetails={ssoProvider.details as SAMLProviderInfo} />;
innerInfoPanel = <SAMLProviderInfoPanel samlProviderDetails={ssoProvider.details as SAMLProviderInfo} />;
break;
case 'oidc':
infoPanel = <OIDCProviderInfoPanel ssoProvider={ssoProvider} />;
innerInfoPanel = <OIDCProviderInfoPanel ssoProvider={ssoProvider} />;
break;
default:
infoPanel = null;
innerInfoPanel = null;
}

const downloadSAMLSigningCertificate = () => {
Expand Down Expand Up @@ -157,7 +163,25 @@ const SSOProviderInfoPanel: FC<{
<Box flexShrink={0} flexGrow={1} fontWeight='bold' ml={theme.spacing(1)} fontSize={'small'}>
Provider Information:
</Box>
{infoPanel}
<FieldsContainer>
{innerInfoPanel}
<Field
label={<Label>Automatically create new users on login</Label>}
value={ssoProvider.config?.auto_provision?.enabled ? 'Yes' : 'No'}
/>
{ssoProvider.config?.auto_provision?.enabled && (
<>
<Field
label={<Label>Allow SSO provider to manage roles for new users</Label>}
value={ssoProvider.config?.auto_provision?.role_provision ? 'Yes' : 'No'}
/>
<Field
label={<Label>Default role when creating new users</Label>}
value={defaultRoleName ?? 'Read-Only'}
/>
</>
)}
</FieldsContainer>
</Paper>
</Paper>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ const SSOConfiguration: FC = () => {
</Grid>
{selectedSSOProvider && (
<Grid item xs={6}>
<SSOProviderInfoPanel ssoProvider={selectedSSOProvider} />
<SSOProviderInfoPanel ssoProvider={selectedSSOProvider} roles={getRolesQuery.data} />
</Grid>
)}
</Grid>
Expand Down

0 comments on commit b21b974

Please sign in to comment.