Skip to content

Commit

Permalink
Auth: Add name to be configurable from the UI (grafana#82144)
Browse files Browse the repository at this point in the history
* Add name to be configurable from the UI

* Update public/app/features/auth-config/ProviderConfigPage.tsx

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* Align test

---------

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
  • Loading branch information
mgyongyosi and Clarity-89 authored Feb 8, 2024
1 parent 19b07fb commit 74d7cd2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('ProviderConfigForm', () => {
{
...testConfig,
settings: {
name: 'GitHub',
allowedOrganizations: 'test-org1,test-org2',
clientId: 'test-client-id',
clientSecret: 'test-client-secret',
Expand Down
7 changes: 5 additions & 2 deletions public/app/features/auth-config/ProviderConfigPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
import { StoreState } from '../../types';

import { ProviderConfigForm } from './ProviderConfigForm';
import { UIMap } from './constants';
import { loadProviders } from './state/actions';
import { SSOProvider } from './types';

Expand All @@ -21,9 +22,11 @@ const getPageNav = (config?: SSOProvider): NavModelItem => {
};
}

const providerDisplayName = UIMap[config.provider][1] || config.provider.toUpperCase();

return {
text: config.settings.name || '',
subTitle: `To configure ${config.settings.name} OAuth2 you must register your application with ${config.settings.name}. ${config.settings.name} will generate a Client ID and Client Secret for you to use.`,
text: providerDisplayName || '',
subTitle: `To configure ${providerDisplayName} OAuth2 you must register your application with ${providerDisplayName}. The provider will generate a Client ID and Client Secret for you to use.`,
icon: config.settings.icon || 'shield',
id: config.provider,
};
Expand Down
14 changes: 2 additions & 12 deletions public/app/features/auth-config/components/ProviderCard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';

import { IconName, isIconName } from '@grafana/data';
import { isIconName } from '@grafana/data';
import { Badge, Card, Icon } from '@grafana/ui';

import { UIMap } from '../constants';
import { getProviderUrl } from '../utils/url';

type Props = {
Expand All @@ -13,17 +14,6 @@ type Props = {
onClick?: () => void;
};

// TODO Remove when this is available from API
const UIMap: Record<string, [IconName, string]> = {
github: ['github', 'GitHub'],
gitlab: ['gitlab', 'GitLab'],
google: ['google', 'Google'],
generic_oauth: ['lock', 'Generic OAuth'],
grafana_com: ['grafana', 'Grafana.com'],
azuread: ['microsoft', 'Azure AD'],
okta: ['okta', 'Okta'],
};

export function ProviderCard({ providerId, enabled, configPath, authType, onClick }: Props) {
//@ts-expect-error
const url = getProviderUrl({ configPath, id: providerId });
Expand Down
13 changes: 13 additions & 0 deletions public/app/features/auth-config/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
import { IconName } from '@grafana/data';

export const BASE_PATH = 'admin/authentication/';

// TODO Remove when this is available from API
export const UIMap: Record<string, [IconName, string]> = {
github: ['github', 'GitHub'],
gitlab: ['gitlab', 'GitLab'],
google: ['google', 'Google'],
generic_oauth: ['lock', 'Generic OAuth'],
grafana_com: ['grafana', 'Grafana.com'],
azuread: ['microsoft', 'Azure AD'],
okta: ['okta', 'Okta'],
};
18 changes: 10 additions & 8 deletions public/app/features/auth-config/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import { isSelectableValue } from './utils/guards';

/** Map providers to their settings */
export const fields: Record<SSOProvider['provider'], Array<keyof SSOProvider['settings']>> = {
github: ['clientId', 'clientSecret', 'teamIds', 'allowedOrganizations'],
google: ['clientId', 'clientSecret', 'allowedDomains'],
gitlab: ['clientId', 'clientSecret', 'allowedOrganizations', 'teamIds'],
azuread: ['clientId', 'clientSecret', 'authUrl', 'tokenUrl', 'scopes', 'allowedGroups', 'allowedDomains'],
github: ['name', 'clientId', 'clientSecret', 'teamIds', 'allowedOrganizations'],
google: ['name', 'clientId', 'clientSecret', 'allowedDomains'],
gitlab: ['name', 'clientId', 'clientSecret', 'allowedOrganizations', 'teamIds'],
azuread: ['name', 'clientId', 'clientSecret', 'authUrl', 'tokenUrl', 'scopes', 'allowedGroups', 'allowedDomains'],
okta: [
'name',
'clientId',
'clientSecret',
'authUrl',
Expand Down Expand Up @@ -221,7 +222,8 @@ export function fieldMap(provider: string): Record<string, FieldData> {
},
name: {
label: 'Display name',
description: 'Helpful if you use more than one identity providers or SSO protocols.',
description:
'Will be displayed on the login page as "Sign in with ...". Helpful if you use more than one identity providers or SSO protocols.',
type: 'text',
},
allowSignUp: {
Expand Down Expand Up @@ -313,17 +315,17 @@ export function fieldMap(provider: string): Record<string, FieldData> {
},
tlsClientCa: {
label: 'TLS client ca',
description: 'The path to the trusted certificate authority list. Is not applicable on Grafana Cloud.',
description: 'The file path to the trusted certificate authority list. Is not applicable on Grafana Cloud.',
type: 'text',
},
tlsClientCert: {
label: 'TLS client cert',
description: 'The path to the certificate. Is not applicable on Grafana Cloud.',
description: 'The file path to the certificate. Is not applicable on Grafana Cloud.',
type: 'text',
},
tlsClientKey: {
label: 'TLS client key',
description: 'The path to the key. Is not applicable on Grafana Cloud.',
description: 'The file path to the key. Is not applicable on Grafana Cloud.',
type: 'text',
},
tlsSkipVerifyInsecure: {
Expand Down

0 comments on commit 74d7cd2

Please sign in to comment.