auth.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import u2f from 'u2f-api';
  2. import {Field} from 'sentry/components/forms/type';
  3. import {Organization} from './organization';
  4. export type AuthenticatorDevice = {
  5. authId: string;
  6. key_handle: string;
  7. name: string;
  8. timestamp?: string;
  9. };
  10. export type Authenticator = {
  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. * String used to display on button for user as CTA to enroll
  33. */
  34. enrollButton: string;
  35. /**
  36. * Is this used as a backup interface?
  37. */
  38. isBackupInterface: boolean;
  39. /**
  40. * Is user enrolled to this authenticator
  41. */
  42. isEnrolled: boolean;
  43. lastUsedAt: string | null;
  44. /**
  45. * Display name for the authenticator
  46. */
  47. name: string;
  48. /**
  49. * String to display on button for user to remove authenticator
  50. */
  51. removeButton: string | null;
  52. rotationWarning: string | null;
  53. status: string;
  54. /**
  55. * The form configuration for the authenticator is present during enrollment
  56. */
  57. form?: Field[];
  58. phone?: string;
  59. secret?: string;
  60. } & Partial<EnrolledAuthenticator> &
  61. (
  62. | {
  63. id: 'sms';
  64. }
  65. | {
  66. id: 'totp';
  67. qrcode: string;
  68. }
  69. | {
  70. challenge: ChallengeData;
  71. id: 'u2f';
  72. }
  73. );
  74. export type ChallengeData = {
  75. // will have only authenticateRequest or registerRequest
  76. authenticateRequests: u2f.SignRequest;
  77. registerRequests: u2f.RegisterRequest;
  78. registeredKeys: u2f.RegisteredKey[];
  79. webAuthnAuthenticationData: string;
  80. // for WebAuthn register
  81. webAuthnRegisterData: string;
  82. };
  83. export type EnrolledAuthenticator = {
  84. authId: string;
  85. createdAt: string;
  86. lastUsedAt: string | null;
  87. name: string;
  88. };
  89. /**
  90. * This is an authenticator that a user is enrolled in
  91. */
  92. export type UserEnrolledAuthenticator = {
  93. dateCreated: EnrolledAuthenticator['createdAt'];
  94. dateUsed: EnrolledAuthenticator['lastUsedAt'];
  95. id: EnrolledAuthenticator['authId'];
  96. name: EnrolledAuthenticator['name'];
  97. type: Authenticator['id'];
  98. };
  99. /**
  100. * XXX(ts): This actually all comes from getsentry. We should definitely
  101. * refactor this into a more proper 'hook' mechanism in the future
  102. */
  103. export type AuthConfig = {
  104. canRegister: boolean;
  105. githubLoginLink: string;
  106. googleLoginLink: string;
  107. hasNewsletter: boolean;
  108. serverHostname: string;
  109. vstsLoginLink: string;
  110. };
  111. export type AuthProvider = {
  112. disables2FA: boolean;
  113. key: string;
  114. name: string;
  115. requiredFeature: string;
  116. };
  117. export enum UserIdentityCategory {
  118. SOCIAL_IDENTITY = 'social-identity',
  119. GLOBAL_IDENTITY = 'global-identity',
  120. ORG_IDENTITY = 'org-identity',
  121. }
  122. export enum UserIdentityStatus {
  123. CAN_DISCONNECT = 'can_disconnect',
  124. NEEDED_FOR_GLOBAL_AUTH = 'needed_for_global_auth',
  125. NEEDED_FOR_ORG_AUTH = 'needed_for_org_auth',
  126. }
  127. export type UserIdentityProvider = {
  128. key: string;
  129. name: string;
  130. };
  131. /**
  132. * UserIdentityConfig is used in Account Identities
  133. */
  134. export type UserIdentityConfig = {
  135. category: UserIdentityCategory;
  136. dateAdded: string | null;
  137. dateSynced: string | null;
  138. dateVerified: string | null;
  139. id: string;
  140. isLogin: boolean;
  141. name: string;
  142. organization: Organization | null;
  143. provider: UserIdentityProvider;
  144. status: UserIdentityStatus;
  145. };