auth.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import type u2f from 'u2f-api';
  2. import type {Field} from 'sentry/components/forms/types';
  3. import type {ControlSiloOrganization} from 'sentry/types/control_silo_organization';
  4. export type AuthenticatorDevice = {
  5. authId: string;
  6. key_handle: string;
  7. name: string;
  8. timestamp?: string;
  9. };
  10. interface BaseAuthenticator extends Partial<Omit<EnrolledAuthenticator, 'createdAt'>> {
  11. /**
  12. * Allows multiple enrollments to authenticator
  13. */
  14. allowMultiEnrollment: boolean;
  15. /**
  16. * Allows authenticator's secret to be rotated without disabling
  17. */
  18. allowRotationInPlace: boolean;
  19. canValidateOtp: boolean;
  20. codes: string[];
  21. /**
  22. * String to display on button for additional information about authenticator
  23. */
  24. configureButton: string;
  25. createdAt: string | null;
  26. /**
  27. * Description of the authenticator
  28. */
  29. description: string;
  30. devices: AuthenticatorDevice[];
  31. /**
  32. * New enrollments of this 2FA interface are not allowed
  33. */
  34. disallowNewEnrollment: boolean;
  35. /**
  36. * String used to display on button for user as CTA to enroll
  37. */
  38. enrollButton: string;
  39. /**
  40. * Is this used as a backup interface?
  41. */
  42. isBackupInterface: boolean;
  43. /**
  44. * Is user enrolled to this authenticator
  45. */
  46. isEnrolled: boolean;
  47. lastUsedAt: string | null;
  48. /**
  49. * Display name for the authenticator
  50. */
  51. name: string;
  52. /**
  53. * String to display on button for user to remove authenticator
  54. */
  55. removeButton: string | null;
  56. rotationWarning: string | null;
  57. status: string;
  58. /**
  59. * The form configuration for the authenticator is present during enrollment
  60. */
  61. form?: Field[];
  62. phone?: string;
  63. secret?: string;
  64. }
  65. export interface TotpAuthenticator extends BaseAuthenticator {
  66. id: 'totp';
  67. qrcode: string;
  68. }
  69. export interface SmsAuthenticator extends BaseAuthenticator {
  70. id: 'sms';
  71. }
  72. export interface U2fAuthenticator extends BaseAuthenticator {
  73. challenge: ChallengeData;
  74. id: 'u2f';
  75. // This may not be set depending on the option 'u2f.skip-session-cookie-allowlist'
  76. state?: StateData;
  77. }
  78. export interface RecoveryAuthenticator extends BaseAuthenticator {
  79. id: 'recovery';
  80. }
  81. export type Authenticator =
  82. | TotpAuthenticator
  83. | SmsAuthenticator
  84. | U2fAuthenticator
  85. | RecoveryAuthenticator;
  86. export type ChallengeData = {
  87. // will have only authenticateRequest or registerRequest
  88. authenticateRequests: u2f.SignRequest;
  89. registerRequests: u2f.RegisterRequest;
  90. registeredKeys: u2f.RegisteredKey[];
  91. webAuthnAuthenticationData: string;
  92. // for WebAuthn register
  93. webAuthnRegisterData: string;
  94. };
  95. export type StateData = {
  96. challenge: string;
  97. user_verification: 'required' | 'preferred' | 'discouraged' | null;
  98. };
  99. export type EnrolledAuthenticator = {
  100. authId: string;
  101. createdAt: string;
  102. lastUsedAt: string | null;
  103. name: string;
  104. };
  105. /**
  106. * This is an authenticator that a user is enrolled in
  107. */
  108. export type UserEnrolledAuthenticator = {
  109. dateCreated: EnrolledAuthenticator['createdAt'];
  110. dateUsed: EnrolledAuthenticator['lastUsedAt'];
  111. id: EnrolledAuthenticator['authId'];
  112. name: EnrolledAuthenticator['name'];
  113. type: Authenticator['id'];
  114. };
  115. /**
  116. * XXX(ts): This actually all comes from getsentry. We should definitely
  117. * refactor this into a more proper 'hook' mechanism in the future
  118. */
  119. export type AuthConfig = {
  120. canRegister: boolean;
  121. githubLoginLink: string;
  122. googleLoginLink: string;
  123. hasNewsletter: boolean;
  124. serverHostname: string;
  125. vstsLoginLink: string;
  126. };
  127. // Users can have SSO providers of their own (social login with github)
  128. // and organizations can have SSO configuration for SAML/google domain/okta.
  129. // https://github.com/getsentry/sentry/pull/52469#discussion_r1258387880
  130. export type AuthProvider = {
  131. key: string;
  132. name: string;
  133. requiredFeature: string;
  134. };
  135. export type OrganizationAuthProvider = {
  136. default_role: string;
  137. id: string;
  138. login_url: string;
  139. pending_links_count: number;
  140. provider_name: string;
  141. require_link: boolean;
  142. scim_enabled: boolean;
  143. };
  144. export enum UserIdentityCategory {
  145. SOCIAL_IDENTITY = 'social-identity',
  146. GLOBAL_IDENTITY = 'global-identity',
  147. ORG_IDENTITY = 'org-identity',
  148. }
  149. export enum UserIdentityStatus {
  150. CAN_DISCONNECT = 'can_disconnect',
  151. NEEDED_FOR_GLOBAL_AUTH = 'needed_for_global_auth',
  152. NEEDED_FOR_ORG_AUTH = 'needed_for_org_auth',
  153. }
  154. export type UserIdentityProvider = {
  155. key: string;
  156. name: string;
  157. };
  158. /**
  159. * UserIdentityConfig is used in Account Identities
  160. */
  161. export type UserIdentityConfig = {
  162. category: UserIdentityCategory;
  163. dateAdded: string | null;
  164. dateSynced: string | null;
  165. dateVerified: string | null;
  166. id: string;
  167. isLogin: boolean;
  168. name: string;
  169. organization: ControlSiloOrganization | null;
  170. provider: UserIdentityProvider;
  171. status: UserIdentityStatus;
  172. };