useThirdPartyAuthentication.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed } from 'vue'
  3. import { storeToRefs } from 'pinia'
  4. import { i18n } from '#shared/i18n.ts'
  5. import { useApplicationStore } from '#shared/stores/application.ts'
  6. import type { ThirdPartyAuthProvider } from '#shared/types/authentication.ts'
  7. export const useThirdPartyAuthentication = () => {
  8. const application = useApplicationStore()
  9. const { config } = storeToRefs(application)
  10. const providers = computed<ThirdPartyAuthProvider[]>(() => {
  11. return [
  12. {
  13. name: i18n.t('Facebook'),
  14. enabled: !!config.value.auth_facebook,
  15. icon: 'facebook',
  16. url: '/auth/facebook',
  17. },
  18. {
  19. name: i18n.t('Twitter'),
  20. enabled: !!config.value.auth_twitter,
  21. icon: 'twitter',
  22. url: '/auth/twitter',
  23. },
  24. {
  25. name: i18n.t('LinkedIn'),
  26. enabled: !!config.value.auth_linkedin,
  27. icon: 'linkedin',
  28. url: '/auth/linkedin',
  29. },
  30. {
  31. name: i18n.t('GitHub'),
  32. enabled: !!config.value.auth_github,
  33. icon: 'github',
  34. url: '/auth/github',
  35. },
  36. {
  37. name: i18n.t('GitLab'),
  38. enabled: !!config.value.auth_gitlab,
  39. icon: 'gitlab',
  40. url: '/auth/gitlab',
  41. },
  42. {
  43. name: i18n.t('Microsoft'),
  44. enabled: !!config.value.auth_microsoft_office365,
  45. icon: 'microsoft',
  46. url: '/auth/microsoft_office365',
  47. },
  48. {
  49. name: i18n.t('Google'),
  50. enabled: !!config.value.auth_google_oauth2,
  51. icon: 'google',
  52. url: '/auth/google_oauth2',
  53. },
  54. {
  55. name: i18n.t('Weibo'),
  56. enabled: !!config.value.auth_weibo,
  57. icon: 'weibo',
  58. url: '/auth/weibo',
  59. },
  60. {
  61. name:
  62. (config.value['auth_saml_credentials.display_name'] as string) ||
  63. i18n.t('SAML'),
  64. enabled: !!config.value.auth_saml,
  65. icon: 'saml',
  66. url: '/auth/saml',
  67. },
  68. {
  69. name: i18n.t('SSO'),
  70. enabled: !!config.value.auth_sso,
  71. icon: 'sso',
  72. url: '/auth/sso',
  73. },
  74. ]
  75. })
  76. const enabledProviders = computed(() => {
  77. return providers.value.filter((provider) => provider.enabled)
  78. })
  79. return {
  80. enabledProviders,
  81. hasEnabledProviders: computed(() => enabledProviders.value.length > 0),
  82. }
  83. }