initializeTwoFactorPlugins.ts 840 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { EnumTwoFactorAuthenticationMethod } from '#shared/graphql/types.ts'
  3. import type {
  4. TwoFactorConfigurationOptions,
  5. TwoFactorPlugin,
  6. } from '../types.ts'
  7. const pluginsModules = import.meta.glob<TwoFactorPlugin>('../plugins/*.ts', {
  8. eager: true,
  9. import: 'default',
  10. })
  11. export const twoFactorPluginsFiles = Object.values(pluginsModules).sort(
  12. (p1, p2) => p1.order - p2.order,
  13. )
  14. export const initializeTwoFactorPlugins = (
  15. twoFactorConfigurationPlugins: Record<
  16. EnumTwoFactorAuthenticationMethod,
  17. TwoFactorConfigurationOptions
  18. >,
  19. ) => {
  20. twoFactorPluginsFiles.forEach((plugin) => {
  21. if (twoFactorConfigurationPlugins[plugin.name]) {
  22. plugin.configurationOptions = twoFactorConfigurationPlugins[plugin.name]
  23. }
  24. })
  25. }