mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-04 12:24:09 +01:00
Added webauthn_enabled
This commit is contained in:
@@ -8,25 +8,14 @@
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-row>
|
||||
<v-col v-if="!authStore.authUser.tfa_enabled" cols="4">
|
||||
<v-col v-if="fidoCreds.length === 0" cols="4">
|
||||
<div tag="p" class="my-4">
|
||||
{{
|
||||
$gettext(
|
||||
'You must enable two-factor authentication using one-time passwords first.'
|
||||
"You don't have any WebAuthN registered as a second authentication method."
|
||||
)
|
||||
}}
|
||||
</div>
|
||||
</v-col>
|
||||
<v-col v-else cols="4">
|
||||
<template v-if="fidoCreds.length === 0">
|
||||
<div tag="p" class="my-4">
|
||||
{{
|
||||
$gettext(
|
||||
"You don't have any WebAuthN registered as a second authentication method."
|
||||
)
|
||||
}}
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="browserCapable">
|
||||
<v-form ref="fidoForm" @submit.prevent="startFidoRegistration">
|
||||
<v-text-field
|
||||
@@ -104,6 +93,12 @@
|
||||
/>
|
||||
</v-form>
|
||||
</ConfirmDialog>
|
||||
<v-dialog v-model="showBackupTokenDialog" max-width="800px" persistent>
|
||||
<RecoveryCodesResetDialog
|
||||
:tokens="newTokens"
|
||||
@close="closeRecoveryCodesResetDialog"
|
||||
/>
|
||||
</v-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
@@ -113,6 +108,7 @@ import { useGettext } from 'vue3-gettext'
|
||||
import rules from '@/plugins/rules.js'
|
||||
import { useAuthStore } from '@/stores'
|
||||
import ConfirmDialog from '@/components/tools/ConfirmDialog.vue'
|
||||
import RecoveryCodesResetDialog from './RecoveryCodesResetDialog.vue'
|
||||
import {
|
||||
create,
|
||||
parseCreationOptionsFromJSON,
|
||||
@@ -145,27 +141,37 @@ const confirmEdition = ref()
|
||||
const editForm = ref()
|
||||
const editName = ref('')
|
||||
const editEnabled = ref(false)
|
||||
const tokens = ref()
|
||||
const showBackupTokenDialog = ref(false)
|
||||
|
||||
async function startFidoRegistration() {
|
||||
registrationLoading.value = true
|
||||
const { valid } = await fidoForm.value.validate()
|
||||
if (!valid) {
|
||||
registrationLoading.value = false
|
||||
return
|
||||
}
|
||||
registrationLoading.value = true
|
||||
const creationOption = await authApi.beginFidoRegistration()
|
||||
if (creationOption) {
|
||||
const options = parseCreationOptionsFromJSON(creationOption.data)
|
||||
const result = await create(options)
|
||||
const response = result.toJSON()
|
||||
console.log(response)
|
||||
response.name = name.value
|
||||
await authStore.addFidoCred(response)
|
||||
const device = await create(options)
|
||||
const result = device.toJSON()
|
||||
result.name = name.value
|
||||
authStore.addFidoCred(result).then((res) => {
|
||||
if (res.status === 200) {
|
||||
tokens.value = res.data.tokens
|
||||
showBackupTokenDialog.value = true
|
||||
}
|
||||
})
|
||||
fidoForm.value.reset()
|
||||
}
|
||||
registrationLoading.value = false
|
||||
}
|
||||
|
||||
function closeRecoveryCodesResetDialog() {
|
||||
tokens.value = []
|
||||
showBackupTokenDialog.value = false
|
||||
}
|
||||
|
||||
async function deleteCred(cred) {
|
||||
const result = await confirmDeletion.value.open(
|
||||
$gettext('Warning'),
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
<span class="headline"> {{ $gettext('WebAuthN registration') }} </span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
|
||||
<v-btn color="success" :loading="registrationLoading" @click="startFidoRegistration">{{ $gettext('Register device') }}</v-btn>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="grey darken-1" text @click="close">
|
||||
{{ $gettext('Close') }}
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { ref, onMounted } from 'vue'
|
||||
|
||||
|
||||
const { $gettext } = useGettext()
|
||||
const name = ref()
|
||||
const registrationLoading = ref(false)
|
||||
const publicKey = ref()
|
||||
|
||||
async function startFidoRegistration() {
|
||||
if (publicKey.value) {
|
||||
navigator.credentials.create(publicKey.value)
|
||||
.then(function (attestation) {
|
||||
// Send new credential info to server for verification and registration.
|
||||
console.log(attestation)
|
||||
})
|
||||
.catch(function (err) {
|
||||
// No acceptable authenticator or user refused consent. Handle appropriately.
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
registrationLoading.value = true
|
||||
authApi.beginFidoRegistration().then((resp) => {
|
||||
publicKey.value = resp.data.publicKey
|
||||
}).finally(() => registrationLoading.value = false)
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close'])
|
||||
function close() {
|
||||
emit('close')
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user