auth.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import u2f from 'u2f-api';
  2. import {Field} from 'sentry/views/settings/components/forms/type';
  3. import {Organization} from './organization';
  4. export type AuthenticatorDevice = {
  5. key_handle: string;
  6. authId: string;
  7. name: string;
  8. timestamp?: string;
  9. };
  10. export type Authenticator = {
  11. /**
  12. * String used to display on button for user as CTA to enroll
  13. */
  14. enrollButton: string;
  15. /**
  16. * Display name for the authenticator
  17. */
  18. name: string;
  19. /**
  20. * Allows multiple enrollments to authenticator
  21. */
  22. allowMultiEnrollment: boolean;
  23. /**
  24. * Allows authenticator's secret to be rotated without disabling
  25. */
  26. allowRotationInPlace: boolean;
  27. /**
  28. * String to display on button for user to remove authenticator
  29. */
  30. removeButton: string | null;
  31. canValidateOtp: boolean;
  32. /**
  33. * Is user enrolled to this authenticator
  34. */
  35. isEnrolled: boolean;
  36. /**
  37. * String to display on button for additional information about authenticator
  38. */
  39. configureButton: string;
  40. /**
  41. * Is this used as a backup interface?
  42. */
  43. isBackupInterface: boolean;
  44. /**
  45. * Description of the authenticator
  46. */
  47. description: string;
  48. rotationWarning: string | null;
  49. status: string;
  50. createdAt: string | null;
  51. lastUsedAt: string | null;
  52. codes: string[];
  53. devices: AuthenticatorDevice[];
  54. phone?: string;
  55. secret?: string;
  56. /**
  57. * The form configuration for the authenticator is present during enrollment
  58. */
  59. form?: Field[];
  60. } & Partial<EnrolledAuthenticator> &
  61. (
  62. | {
  63. id: 'sms';
  64. }
  65. | {
  66. id: 'totp';
  67. qrcode: string;
  68. }
  69. | {
  70. id: 'u2f';
  71. challenge: ChallengeData;
  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. // for WebAuthn register
  80. webAuthnRegisterData: string;
  81. webAuthnAuthenticationData: string;
  82. };
  83. export type EnrolledAuthenticator = {
  84. lastUsedAt: string | null;
  85. createdAt: string;
  86. authId: string;
  87. name: string;
  88. };
  89. /**
  90. * This is an authenticator that a user is enrolled in
  91. */
  92. export type UserEnrolledAuthenticator = {
  93. dateUsed: EnrolledAuthenticator['lastUsedAt'];
  94. dateCreated: EnrolledAuthenticator['createdAt'];
  95. type: Authenticator['id'];
  96. id: EnrolledAuthenticator['authId'];
  97. name: EnrolledAuthenticator['name'];
  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. serverHostname: string;
  106. hasNewsletter: boolean;
  107. githubLoginLink: string;
  108. vstsLoginLink: string;
  109. googleLoginLink: string;
  110. };
  111. export type AuthProvider = {
  112. key: string;
  113. name: string;
  114. requiredFeature: string;
  115. disables2FA: boolean;
  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. id: string;
  137. provider: UserIdentityProvider;
  138. name: string;
  139. status: UserIdentityStatus;
  140. isLogin: boolean;
  141. organization: Organization | null;
  142. dateAdded: string | null;
  143. dateVerified: string | null;
  144. dateSynced: string | null;
  145. };