authenticators.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import type {
  2. RecoveryAuthenticator as RecoveryAuthenticatorType,
  3. SmsAuthenticator as SmsAuthenticatorType,
  4. TotpAuthenticator as TotpAuthenticatorType,
  5. U2fAuthenticator as U2fAuthenticatorType,
  6. } from 'sentry/types';
  7. export function Authenticators(): {
  8. Recovery: (props?: Partial<RecoveryAuthenticatorType>) => RecoveryAuthenticatorType;
  9. Sms: (props?: Partial<SmsAuthenticatorType>) => SmsAuthenticatorType;
  10. Totp: (props?: Partial<TotpAuthenticatorType>) => TotpAuthenticatorType;
  11. U2f: (props?: Partial<U2fAuthenticatorType>) => U2fAuthenticatorType;
  12. } {
  13. return {
  14. Totp: (p = {}) => ({
  15. lastUsedAt: null,
  16. enrollButton: 'Enroll',
  17. description:
  18. 'An authenticator application that supports TOTP (like Google Authenticator or 1Password) can be used to conveniently secure your account. A new token is generated every 30 seconds.',
  19. isEnrolled: true,
  20. removeButton: 'Remove',
  21. id: 'totp',
  22. createdAt: '2018-01-30T17:24:36.554Z',
  23. configureButton: 'Info',
  24. name: 'Authenticator App',
  25. allowMultiEnrollment: false,
  26. disallowNewEnrollment: false,
  27. authId: '15',
  28. canValidateOtp: true,
  29. isBackupInterface: false,
  30. allowRotationInPlace: false,
  31. authenticatorDevice: [],
  32. devices: [],
  33. rotationWarning: null,
  34. status: 'active',
  35. codes: ['123-456'],
  36. qrcode: 'qr-code',
  37. ...p,
  38. }),
  39. Sms: (p = {}) => ({
  40. createdAt: '2018-01-30T17:24:36.554Z',
  41. lastUsedAt: null,
  42. enrollButton: 'Enroll',
  43. name: 'Text Message',
  44. allowMultiEnrollment: false,
  45. removeButton: 'Remove',
  46. canValidateOtp: true,
  47. isEnrolled: false,
  48. configureButton: 'Info',
  49. id: 'sms',
  50. isBackupInterface: false,
  51. disallowNewEnrollment: false,
  52. allowRotationInPlace: false,
  53. authenticatorDevice: [],
  54. devices: [],
  55. rotationWarning: null,
  56. status: 'active',
  57. codes: ['123-456'],
  58. qrcode: 'qr-code',
  59. description:
  60. "This authenticator sends you text messages for verification. It's useful as a backup method or when you do not have a phone that supports an authenticator application.",
  61. ...p,
  62. }),
  63. U2f: (p = {}) => ({
  64. lastUsedAt: null,
  65. enrollButton: 'Enroll',
  66. description:
  67. "Authenticate with a U2F hardware device. This is a device like a Yubikey or something similar which supports FIDO's U2F specification. This also requires a browser which supports this system (like Google Chrome).",
  68. isEnrolled: true,
  69. removeButton: 'Remove',
  70. id: 'u2f',
  71. createdAt: '2018-01-30T20:56:45.932Z',
  72. configureButton: 'Configure',
  73. name: 'U2F (Universal 2nd Factor)',
  74. allowMultiEnrollment: true,
  75. disallowNewEnrollment: false,
  76. authId: '23',
  77. canValidateOtp: false,
  78. isBackupInterface: false,
  79. allowRotationInPlace: false,
  80. devices: [],
  81. rotationWarning: null,
  82. status: 'active',
  83. codes: [],
  84. challenge: {
  85. webAuthnAuthenticationData: 'webAuthnAuthenticationData',
  86. authenticateRequests: {
  87. version: 'U2F_V2',
  88. appId: 'https://sentry.io',
  89. keyHandle: 'keyHandle',
  90. challenge: 'challenge',
  91. },
  92. registerRequests: {
  93. version: 'U2F_V2',
  94. appId: 'https://sentry.io',
  95. challenge: 'challenge',
  96. },
  97. registeredKeys: [],
  98. // for WebAuthn register
  99. webAuthnRegisterData: 'webAuthnRegisterData',
  100. },
  101. ...p,
  102. }),
  103. Recovery: (p = {}) => ({
  104. id: 'recovery',
  105. lastUsedAt: null,
  106. enrollButton: 'Activate',
  107. allowRotationInPlace: false,
  108. devices: [],
  109. disallowNewEnrollment: false,
  110. rotationWarning: null,
  111. status: 'active',
  112. description:
  113. 'Recovery codes are the only way to access your account if you lose your device and cannot receive two-factor authentication codes.',
  114. isEnrolled: true,
  115. removeButton: null,
  116. createdAt: '2018-01-30T17:24:36.570Z',
  117. configureButton: 'View Codes',
  118. name: 'Recovery Codes',
  119. allowMultiEnrollment: false,
  120. authId: '16',
  121. canValidateOtp: true,
  122. isBackupInterface: true,
  123. codes: ['ABCD-1234', 'EFGH-5678'],
  124. ...p,
  125. }),
  126. };
  127. }
  128. export function AllAuthenticators() {
  129. return Object.values(Authenticators()).map(x => x());
  130. }