mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-12-03 22:01:45 +01:00
1 line
9.8 KiB
Plaintext
1 line
9.8 KiB
Plaintext
{"version":3,"file":"WebAuthn-BHud-m0I.js","sources":["../../../resources/js/views/settings/WebAuthn.vue"],"sourcesContent":["<script setup>\n import SettingTabs from '@/layouts/SettingTabs.vue'\n import userService from '@/services/userService'\n import { webauthnService } from '@/services/webauthn/webauthnService'\n import { useAppSettingsStore } from '@/stores/appSettings'\n import { useUserStore } from '@/stores/user'\n import { useNotifyStore } from '@/stores/notify'\n import { UseColorMode } from '@vueuse/components'\n import Spinner from '@/components/Spinner.vue'\n\n const $2fauth = inject('2fauth')\n const user = useUserStore()\n const appSettings = useAppSettingsStore()\n const notify = useNotifyStore()\n const router = useRouter()\n const returnTo = useStorage($2fauth.prefix + 'returnTo', 'accounts')\n\n const credentials = ref([])\n const isFetching = ref(false)\n\n const isDisabled = computed(() => {\n return (appSettings.enableSso && appSettings.useSsoOnly) || user.authenticated_by_proxy\n })\n \n onMounted(() => {\n fetchCredentials()\n })\n\n watch(() => user.preferences.useWebauthnOnly, () => {\n userService.updatePreference('useWebauthnOnly', user.preferences.useWebauthnOnly).then(response => {\n notify.success({ text: trans('settings.forms.setting_saved') })\n })\n })\n\n /**\n * Register a new security device\n */\n function register() {\n if (isDisabled.value == true) {\n notify.warn({text: trans('errors.unsupported_with_reverseproxy') })\n return false\n }\n\n webauthnService.register().then((response) => {\n router.push({ name: 'settings.webauthn.editCredential', params: { credentialId: JSON.parse(response.config.data).id } })\n })\n .catch(error => {\n if ('webauthn' in error) {\n if (error.name == 'is-warning') {\n notify.warn({ text: trans(error.message) })\n }\n else notify.alert({ text: trans(error.message) })\n }\n else if( error.response?.status === 422 ) {\n notify.alert({ text: error.response.data.message })\n }\n else {\n notify.error(error);\n }\n })\n }\n\n /**\n * revoke a credential\n */\n function revokeCredential(credentialId) {\n if(confirm(trans('auth.confirm.revoke_device'))) {\n userService.revokeWebauthnDevice(credentialId).then(response => {\n // Remove the revoked credential from the collection\n credentials.value = credentials.value.filter(a => a.id !== credentialId)\n\n // Then we disable the useWebauthnOnly preference which is relevant\n // only when at least one device is registered\n if (credentials.value.length == 0) {\n user.preferences.useWebauthnOnly = false\n }\n\n notify.success({ text: trans('auth.webauthn.device_revoked') })\n });\n }\n }\n\n /**\n * Always display a printable name\n */\n function displayName(credential) {\n return credential.alias ? credential.alias : trans('auth.webauthn.my_device') + ' (#' + credential.id.substring(0, 10) + ')'\n }\n\n /**\n * Get all credentials from backend\n */\n function fetchCredentials() {\n isFetching.value = true\n\n userService.getWebauthnDevices({returnError: true})\n .then(response => {\n credentials.value = response.data\n })\n .catch(error => {\n if( error.response.status === 405 ) {\n // The backend returns a 405 response if the user is authenticated by a reverse proxy\n // or if SSO only is enabled.\n // The form is already disabled (see isDisabled) so we do nothing more here\n }\n else {\n notify.error(error)\n }\n })\n .finally(() => {\n isFetching.value = false\n })\n }\n\n onBeforeRouteLeave((to) => {\n if (! to.name.startsWith('settings.')) {\n notify.clear()\n }\n })\n</script>\n\n<template>\n <div>\n <SettingTabs :activeTab=\"'settings.webauthn.devices'\" />\n <div class=\"options-tabs\">\n <FormWrapper>\n <div v-if=\"isDisabled && user.oauth_provider\" class=\"notification is-warning has-text-centered\">\n {{ $t('auth.sso_only_x_settings_are_disabled', { auth_method: 'WebAuthn' }) }}\n </div>\n <div v-if=\"isDisabled && user.authenticated_by_proxy\" class=\"notification is-warning has-text-centered\" v-html=\"$t('auth.auth_handled_by_proxy')\" />\n <h4 class=\"title is-4 has-text-grey-light\">{{ $t('auth.webauthn.security_devices') }}</h4>\n <div class=\"is-size-7-mobile\">\n {{ $t('auth.webauthn.security_devices_legend')}}\n </div>\n <div class=\"mt-3\">\n <a tabindex=\"0\" @click=\"register\" @keyup.enter=\"register\">\n <FontAwesomeIcon :icon=\"['fas', 'plus-circle']\" /> {{ $t('auth.webauthn.register_a_new_device')}}\n </a>\n </div>\n <!-- credentials list -->\n <div v-if=\"credentials.length > 0\" class=\"field\">\n <div v-for=\"credential in credentials\" :key=\"credential.id\" class=\"group-item is-size-5 is-size-6-mobile\">\n {{ displayName(credential) }}\n <!-- revoke link -->\n <UseColorMode v-slot=\"{ mode }\">\n <button type=\"button\" class=\"button tag is-pulled-right\" :class=\"mode === 'dark' ? 'is-dark':'is-white'\" @click=\"revokeCredential(credential.id)\" :title=\"$t('settings.revoke')\">\n {{ $t('settings.revoke') }}\n </button>\n </UseColorMode>\n <!-- edit link -->\n <!-- <RouterLink :to=\"{ name: '' }\" class=\"has-text-grey pl-1\" :title=\"$t('commons.rename')\">\n <FontAwesomeIcon :icon=\"['fas', 'pen-square']\" />\n </RouterLink> -->\n </div>\n <div class=\"mt-2 is-size-7 is-pulled-right\">\n {{ $t('auth.webauthn.revoking_a_device_is_permanent')}}\n </div>\n </div>\n <Spinner :isVisible=\"isFetching && credentials.length === 0\" />\n <h4 class=\"title is-4 pt-6 has-text-grey-light\">{{ $t('auth.webauthn.options') }}</h4>\n <div class=\"field\">\n {{ $t('auth.webauthn.need_a_security_device_to_enable_options')}}\n </div>\n <form>\n <!-- use webauthn only -->\n <FormCheckbox\n v-model=\"user.preferences.useWebauthnOnly\"\n fieldName=\"useWebauthnOnly\"\n label=\"auth.webauthn.use_webauthn_only.label\"\n help=\"auth.webauthn.use_webauthn_only.help\"\n :isDisabled=\"isDisabled || credentials.length === 0\"\n />\n </form>\n <!-- footer -->\n <VueFooter :showButtons=\"true\">\n <ButtonBackCloseCancel :returnTo=\"{ name: returnTo }\" action=\"close\" />\n </VueFooter>\n </FormWrapper>\n </div>\n </div>\n</template>"],"names":["$2fauth","inject","user","useUserStore","appSettings","useAppSettingsStore","notify","useNotifyStore","router","useRouter","returnTo","useStorage","credentials","ref","isFetching","isDisabled","computed","onMounted","fetchCredentials","watch","userService","response","trans","register","webauthnService","error","_a","revokeCredential","credentialId","a","displayName","credential","onBeforeRouteLeave","to"],"mappings":"g1BAUI,MAAMA,EAAUC,EAAO,QAAQ,EACzB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