mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
* Add initial authentication config page skeleton * Add initial SAML config page WIP * Add few more pages * Add connect to IdP page * Assertion mappings page stub and url params * Able to save settings * Some tweaks for authentication page * Tweak behaviour * Tweak provider name * Move SAML config pages to enterprise * minor refactor * Able to reset settings * Configure key and cert from UI * Refactor WIP * Tweak styles * Optional save button * Some tweaks for the page * Don't show info popup when save settings * Improve key/cert validation * Fetch provider status and display on auth page * Add settings list to the auth page * Show call to action card if no auth configured * clean up * Show authentication page only if SAML available * Add access control for SSO config page * Add feature toggle for auth config UI * Add code owners for auth config page * Auth config UI disabled by default * Fix feature toggle check * Apply suggestions from review * Refactor: use forms for steps * Clean up * Improve authentication page loading * Fix CTA link * Minor tweaks * Fix page route * Fix formatting * Fix generated code formatting
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { AuthProviderStatus, Settings, SettingsSection } from 'app/types';
|
|
|
|
import { AuthProviderInfo, GetStatusHook } from './types';
|
|
|
|
export * from './types';
|
|
|
|
const registeredAuthProviders: AuthProviderInfo[] = [];
|
|
const authProvidersConfigHooks: Record<string, GetStatusHook> = {};
|
|
|
|
export function registerAuthProvider(provider: AuthProviderInfo, getConfigHook?: GetStatusHook) {
|
|
if (!registeredAuthProviders.find((p) => p.id === provider.id)) {
|
|
registeredAuthProviders.push(provider);
|
|
if (getConfigHook) {
|
|
authProvidersConfigHooks[provider.id] = getConfigHook;
|
|
}
|
|
}
|
|
}
|
|
|
|
export function getRegisteredAuthProviders(): AuthProviderInfo[] {
|
|
return registeredAuthProviders;
|
|
}
|
|
|
|
export function getAuthProviderInfo(provider: string) {
|
|
return registeredAuthProviders.find((p) => p.id === provider);
|
|
}
|
|
|
|
export function getAuthProviders(cfg: Settings): SettingsSection[] {
|
|
const providers: SettingsSection[] = [];
|
|
for (const [section, sectionConfig] of Object.entries(cfg)) {
|
|
const provider = registeredAuthProviders.find((provider) => `auth.${provider.id}` === section);
|
|
if (provider) {
|
|
const providerData = {
|
|
...sectionConfig,
|
|
providerId: provider.id,
|
|
displayName: sectionConfig.name || provider.displayName,
|
|
};
|
|
providers.push(providerData);
|
|
}
|
|
}
|
|
return providers;
|
|
}
|
|
|
|
export async function getAuthProviderStatus(providerId: string): Promise<AuthProviderStatus> {
|
|
if (authProvidersConfigHooks[providerId]) {
|
|
const getStatusHook = authProvidersConfigHooks[providerId];
|
|
return getStatusHook();
|
|
}
|
|
return { configured: false, enabled: false };
|
|
}
|