index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import {t} from 'sentry/locale';
  2. import type {AuthProvider} from 'sentry/types/auth';
  3. import type {Organization} from 'sentry/types/organization';
  4. import routeTitleGen from 'sentry/utils/routeTitle';
  5. import withOrganization from 'sentry/utils/withOrganization';
  6. import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
  7. import OrganizationAuthList from './organizationAuthList';
  8. type Props = DeprecatedAsyncView['props'] & {
  9. organization: Organization;
  10. };
  11. type State = DeprecatedAsyncView['state'] & {
  12. provider: AuthProvider | null;
  13. providerList: AuthProvider[] | null;
  14. };
  15. class OrganizationAuth extends DeprecatedAsyncView<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<DeprecatedAsyncView['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. getTitle() {
  37. return routeTitleGen(t('Auth Settings'), this.props.organization.slug, false);
  38. }
  39. /**
  40. * TODO(epurkhiser): This does not work right now as we still fallback to the
  41. * old SSO auth configuration page
  42. */
  43. handleConfigure = (provider: AuthProvider) => {
  44. const {organization} = this.props;
  45. this.setState({busy: true});
  46. this.api.request(`/organizations/${organization.slug}/auth-provider/`, {
  47. method: 'POST',
  48. data: {provider, init: true},
  49. success: data => {
  50. // Redirect to auth provider URL
  51. if (data?.auth_url) {
  52. window.location.href = data.auth_url;
  53. }
  54. },
  55. error: () => {
  56. this.setState({busy: false});
  57. },
  58. });
  59. };
  60. /**
  61. * TODO(epurkhiser): This does not work right now as we still fallback to the
  62. * old SSO auth configuration page
  63. */
  64. handleDisableProvider = (provider: AuthProvider) => {
  65. const {organization} = this.props;
  66. this.setState({busy: true});
  67. this.api.request(`/organizations/${organization.slug}/auth-provider/`, {
  68. method: 'DELETE',
  69. data: {provider},
  70. success: () => {
  71. this.setState({provider: null, busy: false});
  72. },
  73. error: () => {
  74. this.setState({busy: false});
  75. },
  76. });
  77. };
  78. renderBody() {
  79. const {providerList, provider} = this.state;
  80. if (providerList === null) {
  81. return null;
  82. }
  83. if (this.props.organization.access.includes('org:write') && provider) {
  84. // If SSO provider is configured, keep showing loading while we redirect
  85. // to django configuration view
  86. return this.renderLoading();
  87. }
  88. const activeProvider = providerList?.find(p => p.key === provider?.key);
  89. return (
  90. <OrganizationAuthList activeProvider={activeProvider} providerList={providerList} />
  91. );
  92. }
  93. }
  94. export default withOrganization(OrganizationAuth);