index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent';
  2. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  3. import {t} from 'sentry/locale';
  4. import type {AuthProvider} from 'sentry/types/auth';
  5. import type {Organization} from 'sentry/types/organization';
  6. import withOrganization from 'sentry/utils/withOrganization';
  7. import OrganizationAuthList from './organizationAuthList';
  8. type Props = DeprecatedAsyncComponent['props'] & {
  9. organization: Organization;
  10. };
  11. type State = DeprecatedAsyncComponent['state'] & {
  12. provider: AuthProvider | null;
  13. providerList: AuthProvider[] | null;
  14. };
  15. class OrganizationAuth extends DeprecatedAsyncComponent<Props, State> {
  16. componentDidUpdate() {
  17. const {organization} = this.props;
  18. const access = organization.access;
  19. if (this.state.provider && access.includes('org:write')) {
  20. // If SSO provider is configured, keep showing loading while we redirect
  21. // to django configuration view
  22. // XXX: This does not need to be normalized for customer-domains because we're going
  23. // to a django rendered view.
  24. const path = `/organizations/${organization.slug}/auth/configure/`;
  25. // Use replace so we don't go back to the /settings/auth and hit this path again.
  26. window.location.replace(path);
  27. }
  28. }
  29. getEndpoints(): ReturnType<DeprecatedAsyncComponent['getEndpoints']> {
  30. const {organization} = this.props;
  31. return [
  32. ['providerList', `/organizations/${organization.slug}/auth-providers/`],
  33. ['provider', `/organizations/${organization.slug}/auth-provider/`],
  34. ];
  35. }
  36. /**
  37. * TODO(epurkhiser): This does not work right now as we still fallback to the
  38. * old SSO auth configuration page
  39. */
  40. handleConfigure = (provider: AuthProvider) => {
  41. const {organization} = this.props;
  42. this.setState({busy: true});
  43. this.api.request(`/organizations/${organization.slug}/auth-provider/`, {
  44. method: 'POST',
  45. data: {provider, init: true},
  46. success: data => {
  47. // Redirect to auth provider URL
  48. if (data?.auth_url) {
  49. window.location.href = data.auth_url;
  50. }
  51. },
  52. error: () => {
  53. this.setState({busy: false});
  54. },
  55. });
  56. };
  57. /**
  58. * TODO(epurkhiser): This does not work right now as we still fallback to the
  59. * old SSO auth configuration page
  60. */
  61. handleDisableProvider = (provider: AuthProvider) => {
  62. const {organization} = this.props;
  63. this.setState({busy: true});
  64. this.api.request(`/organizations/${organization.slug}/auth-provider/`, {
  65. method: 'DELETE',
  66. data: {provider},
  67. success: () => {
  68. this.setState({provider: null, busy: false});
  69. },
  70. error: () => {
  71. this.setState({busy: false});
  72. },
  73. });
  74. };
  75. renderBody() {
  76. const {organization} = this.props;
  77. const {providerList, provider} = this.state;
  78. if (providerList === null) {
  79. return null;
  80. }
  81. if (this.props.organization.access.includes('org:write') && provider) {
  82. // If SSO provider is configured, keep showing loading while we redirect
  83. // to django configuration view
  84. return this.renderLoading();
  85. }
  86. const activeProvider = providerList?.find(p => p.key === provider?.key);
  87. return (
  88. <SentryDocumentTitle title={t('Auth Settings')} orgSlug={organization.slug}>
  89. <OrganizationAuthList
  90. activeProvider={activeProvider}
  91. providerList={providerList}
  92. />
  93. </SentryDocumentTitle>
  94. );
  95. }
  96. }
  97. export default withOrganization(OrganizationAuth);