organizationAuthList.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import EmptyMessage from 'sentry/components/emptyMessage';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {Panel, PanelAlert, PanelBody, PanelHeader} from 'sentry/components/panels';
  4. import {t, tct} from 'sentry/locale';
  5. import {AuthProvider, Organization} from 'sentry/types';
  6. import {descopeFeatureName} from 'sentry/utils';
  7. import getCsrfToken from 'sentry/utils/getCsrfToken';
  8. import withOrganization from 'sentry/utils/withOrganization';
  9. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  10. import PermissionAlert from 'sentry/views/settings/organization/permissionAlert';
  11. import ProviderItem from './providerItem';
  12. const PROVIDER_POPULARITY: Record<string, number> = {
  13. google: 0,
  14. github: 1,
  15. okta: 2,
  16. 'active-directory': 3,
  17. saml2: 4,
  18. onelogin: 5,
  19. rippling: 6,
  20. auth0: 7,
  21. jumpcloud: 8,
  22. };
  23. type Props = {
  24. organization: Organization;
  25. providerList: AuthProvider[];
  26. activeProvider?: AuthProvider;
  27. };
  28. function OrganizationAuthList({organization, providerList, activeProvider}: Props) {
  29. const features = organization.features;
  30. // Sort provider list twice: first, by popularity,
  31. // and then a second time, to sort unavailable providers for the current plan to the end of the list.
  32. const sortedByPopularity = (providerList ?? []).sort((a, b) => {
  33. if (!(a.key in PROVIDER_POPULARITY)) {
  34. return -1;
  35. }
  36. if (!(b.key in PROVIDER_POPULARITY)) {
  37. return 1;
  38. }
  39. if (PROVIDER_POPULARITY[a.key] === PROVIDER_POPULARITY[b.key]) {
  40. return 0;
  41. }
  42. return PROVIDER_POPULARITY[a.key] > PROVIDER_POPULARITY[b.key] ? 1 : -1;
  43. });
  44. const list = sortedByPopularity.sort((a, b) => {
  45. const aEnabled = features.includes(descopeFeatureName(a.requiredFeature));
  46. const bEnabled = features.includes(descopeFeatureName(b.requiredFeature));
  47. if (aEnabled === bEnabled) {
  48. return 0;
  49. }
  50. return aEnabled ? -1 : 1;
  51. });
  52. const warn2FADisable =
  53. organization.require2FA &&
  54. list.some(({requiredFeature}) =>
  55. features.includes(descopeFeatureName(requiredFeature))
  56. );
  57. return (
  58. <div className="sso">
  59. <SettingsPageHeader title="Authentication" />
  60. <PermissionAlert />
  61. <Panel>
  62. <PanelHeader>{t('Choose a provider')}</PanelHeader>
  63. <PanelBody>
  64. {!activeProvider && (
  65. <PanelAlert type="info">
  66. {tct(
  67. 'Get started with Single Sign-on for your organization by selecting a provider. Read more in our [link:SSO documentation].',
  68. {
  69. link: (
  70. <ExternalLink href="https://docs.sentry.io/product/accounts/sso/" />
  71. ),
  72. }
  73. )}
  74. </PanelAlert>
  75. )}
  76. {warn2FADisable && (
  77. <PanelAlert type="warning">
  78. {t('Require 2FA will be disabled if you enable SSO.')}
  79. </PanelAlert>
  80. )}
  81. <form
  82. action={`/organizations/${organization.slug}/auth/configure/`}
  83. method="POST"
  84. >
  85. <input type="hidden" name="csrfmiddlewaretoken" value={getCsrfToken()} />
  86. <input type="hidden" name="init" value="1" />
  87. {list.map(provider => (
  88. <ProviderItem
  89. key={provider.key}
  90. provider={provider}
  91. active={!!activeProvider && provider.key === activeProvider.key}
  92. />
  93. ))}
  94. {list.length === 0 && (
  95. <EmptyMessage>
  96. {t('No authentication providers are available.')}
  97. </EmptyMessage>
  98. )}
  99. </form>
  100. </PanelBody>
  101. </Panel>
  102. </div>
  103. );
  104. }
  105. export default withOrganization(OrganizationAuthList);