auth.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import u2f from 'u2f-api';
  2. import {Field} from 'sentry/views/settings/components/forms/type';
  3. export type AuthenticatorDevice = {
  4. key_handle: string;
  5. authId: string;
  6. name: string;
  7. timestamp?: string;
  8. };
  9. export type Authenticator = {
  10. /**
  11. * String used to display on button for user as CTA to enroll
  12. */
  13. enrollButton: string;
  14. /**
  15. * Display name for the authenticator
  16. */
  17. name: string;
  18. /**
  19. * Allows multiple enrollments to authenticator
  20. */
  21. allowMultiEnrollment: boolean;
  22. /**
  23. * Allows authenticator's secret to be rotated without disabling
  24. */
  25. allowRotationInPlace: boolean;
  26. /**
  27. * String to display on button for user to remove authenticator
  28. */
  29. removeButton: string | null;
  30. canValidateOtp: boolean;
  31. /**
  32. * Is user enrolled to this authenticator
  33. */
  34. isEnrolled: boolean;
  35. /**
  36. * String to display on button for additional information about authenticator
  37. */
  38. configureButton: string;
  39. /**
  40. * Is this used as a backup interface?
  41. */
  42. isBackupInterface: boolean;
  43. /**
  44. * Description of the authenticator
  45. */
  46. description: string;
  47. rotationWarning: string | null;
  48. status: string;
  49. createdAt: string | null;
  50. lastUsedAt: string | null;
  51. codes: string[];
  52. devices: AuthenticatorDevice[];
  53. phone?: string;
  54. secret?: string;
  55. /**
  56. * The form configuration for the authenticator is present during enrollment
  57. */
  58. form?: Field[];
  59. } & Partial<EnrolledAuthenticator> &
  60. (
  61. | {
  62. id: 'sms';
  63. }
  64. | {
  65. id: 'totp';
  66. qrcode: string;
  67. }
  68. | {
  69. id: 'u2f';
  70. challenge: ChallengeData;
  71. }
  72. );
  73. export type ChallengeData = {
  74. // will have only authenticateRequest or registerRequest
  75. authenticateRequests: u2f.SignRequest;
  76. registerRequests: u2f.RegisterRequest;
  77. registeredKeys: u2f.RegisteredKey[];
  78. };
  79. export type EnrolledAuthenticator = {
  80. lastUsedAt: string | null;
  81. createdAt: string;
  82. authId: string;
  83. name: string;
  84. };
  85. /**
  86. * This is an authenticator that a user is enrolled in
  87. */
  88. export type UserEnrolledAuthenticator = {
  89. dateUsed: EnrolledAuthenticator['lastUsedAt'];
  90. dateCreated: EnrolledAuthenticator['createdAt'];
  91. type: Authenticator['id'];
  92. id: EnrolledAuthenticator['authId'];
  93. name: EnrolledAuthenticator['name'];
  94. };