useThirdPartyAuthentication.ts 2.9 KB

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