Files
grafana/public/app/features/auth-config/AuthProvidersListPage.tsx

118 lines
3.7 KiB
TypeScript
Raw Normal View History

import React, { JSX, useEffect, useState } from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { GrafanaEdition } from '@grafana/data/src/types/config';
import { reportInteraction } from '@grafana/runtime';
import { Grid, TextLink, ToolbarButton } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page';
import { config } from 'app/core/config';
import { StoreState } from 'app/types';
import AuthDrawer from './AuthDrawer';
import ConfigureAuthCTA from './components/ConfigureAuthCTA';
import { ProviderCard } from './components/ProviderCard';
import { loadSettings } from './state/actions';
import { getRegisteredAuthProviders } from './index';
interface OwnProps {}
export type Props = OwnProps & ConnectedProps<typeof connector>;
function mapStateToProps(state: StoreState) {
const { isLoading, providerStatuses, providers } = state.authConfig;
return {
isLoading,
providerStatuses,
providers,
};
}
const mapDispatchToProps = {
loadSettings,
};
const connector = connect(mapStateToProps, mapDispatchToProps);
export const AuthConfigPageUnconnected = ({
providerStatuses,
isLoading,
loadSettings,
providers,
}: Props): JSX.Element => {
useEffect(() => {
loadSettings();
}, [loadSettings]);
const [showDrawer, setShowDrawer] = useState(false);
const authProviders = getRegisteredAuthProviders();
const availableProviders = authProviders.filter((p) => !providerStatuses[p.id]?.hide);
const onProviderCardClick = (providerType: string, enabled: boolean) => {
reportInteraction('authentication_ui_provider_clicked', { provider: providerType, enabled });
};
// filter out saml from sso providers because it is already included in availableProviders
providers = providers.filter((p) => p.provider !== 'saml');
const providerList = availableProviders.length
? [
...availableProviders.map((p) => ({
provider: p.id,
settings: { ...providerStatuses[p.id], configPath: p.configPath, type: p.type },
})),
...providers,
]
: providers;
return (
<Page
navId="authentication"
subTitle={
<>
Manage your auth settings and configure single sign-on. Find out more in our{' '}
<TextLink
external={true}
href="https://grafana.com/docs/grafana/next/setup-grafana/configure-security/configure-authentication"
>
documentation
</TextLink>
.
</>
}
actions={
config.buildInfo.edition !== GrafanaEdition.OpenSource && (
<ToolbarButton icon="cog" variant="canvas" onClick={() => setShowDrawer(true)}>
Auth settings
</ToolbarButton>
)
}
>
<Page.Contents isLoading={isLoading}>
{!providerList.length ? (
<ConfigureAuthCTA />
) : (
<Grid gap={3} minColumnWidth={34}>
{providerList
SSO Config: Add generic OAuth (#79972) * Setup route * Set up the page * Add orgs * Load settings * Make API call * Remove log * Add FormPrompt * Update types * Add tests * Fix tests * Cleanup * Load settings * Fix naming * Switch to PUT endpoint * Switch to CSS object * Setup fields * Render fields * Extend types * Dynamic provider page * Rename page * Filter out non-implemented providers * Fix types * Add teamIDs validation * Update tests * Fix URL * Update name * Send full data * Add password input * Update test * Expand default values * Fix test * Use SecretInput * Remove dev mode for the feature toggle * Convert fields * Remove fieldFormat utils * Update fields logic * Update tests * Update betterer * SSO: Add Generic OAuth page * SSO: Add Generic OAuth page * SSO: Make client secret not required * Update field name * Revert feature toggle to dev mode * Use provider endpoint * Fix form state check * Update tests * Fix URL redirect after form submit * Mock locationService * Separate Form component * Update fields * Add more fields * Add more fields * Fix spacing * Add UserMapping fields * Add rest of the fields * Add FieldRenderer * Update types * Update comment * Update feature toggle * Add checkbox * Do not submit form if there are errors * Fix revalidation * Redirect on success only * Fix redirect behavior * Add missing descriptions * Use inline checkbox * Add enabled field * Restore feature toggle * Remove source field from PUT request * Add URL to the fields * Add hidden prop to fields and sections * Add Delete button * Prettier * Add authStyle, still not working, description updates * Fix saving select values * Run prettier * Use defaultValue in Select field --------- Co-authored-by: Mihaly Gyongyosi <mgyongyosi@users.noreply.github.com>
2024-01-11 11:23:38 +01:00
// Temporarily filter out providers that don't have the UI implemented
.filter(({ provider }) => !['grafana_com'].includes(provider))
.map(({ provider, settings }) => (
<ProviderCard
key={provider}
authType={settings.type || 'OAuth'}
providerId={provider}
enabled={settings.enabled}
onClick={() => onProviderCardClick(provider, settings.enabled)}
//@ts-expect-error Remove legacy types
configPath={settings.configPath}
/>
))}
{showDrawer && <AuthDrawer onClose={() => setShowDrawer(false)}></AuthDrawer>}
</Grid>
)}
</Page.Contents>
</Page>
);
};
export default connector(AuthConfigPageUnconnected);