Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2FA Setup Key #1008

Merged
merged 5 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const enabling = ref(false);
const confirming = ref(false);
const disabling = ref(false);
const qrCode = ref(null);
const setupKey = ref(null);
const recoveryCodes = ref([]);

const confirmationForm = useForm({
Expand All @@ -36,6 +37,7 @@ const enableTwoFactorAuthentication = () => {
preserveScroll: true,
onSuccess: () => Promise.all([
showQrCode(),
showSetupKey(),
showRecoveryCodes(),
]),
onFinish: () => {
Expand All @@ -51,6 +53,12 @@ const showQrCode = () => {
});
};

const showSetupKey = () => {
return axios.get('/user/two-factor-secret-key').then(response => {
setupKey.value = response.data.secretKey;
});
}

const showRecoveryCodes = () => {
return axios.get('/user/two-factor-recovery-codes').then(response => {
recoveryCodes.value = response.data;
Expand All @@ -64,6 +72,7 @@ const confirmTwoFactorAuthentication = () => {
onSuccess: () => {
confirming.value = false;
qrCode.value = null;
setupKey.value = null;
},
});
};
Expand Down Expand Up @@ -120,16 +129,22 @@ const disableTwoFactorAuthentication = () => {
<div v-if="qrCode">
<div class="mt-4 max-w-xl text-sm text-gray-600">
<p v-if="confirming" class="font-semibold">
To finish enabling two factor authentication, scan the following QR code using your phone's authenticator application and provide the generated OTP code.
To finish enabling two factor authentication, scan the following QR code using your phone's authenticator application or enter the setup key and provide the generated OTP code.
</p>

<p v-else>
Two factor authentication is now enabled. Scan the following QR code using your phone's authenticator application.
Two factor authentication is now enabled. Scan the following QR code using your phone's authenticator application or enter the setup key.
</p>
</div>

<div class="mt-4" v-html="qrCode" />

<div class="mt-4 max-w-xl text-sm text-gray-600">
<p class="font-semibold">
Setup Key: <span v-html="setupKey"></span>
</p>
</div>

<div v-if="confirming" class="mt-4">
<JetLabel for="code" value="Code" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
<div class="mt-4 max-w-xl text-sm text-gray-600">
<p class="font-semibold">
@if ($showingConfirmation)
{{ __('To finish enabling two factor authentication, scan the following QR code using your phone\'s authenticator application and provide the generated OTP code.') }}
{{ __('To finish enabling two factor authentication, scan the following QR code using your phone\'s authenticator application or enter the setup key and provide the generated OTP code.') }}
@else
{{ __('Two factor authentication is now enabled. Scan the following QR code using your phone\'s authenticator application.') }}
{{ __('Two factor authentication is now enabled. Scan the following QR code using your phone\'s authenticator application or enter the setup key.') }}
@endif
</p>
</div>
Expand All @@ -42,6 +42,12 @@
{!! $this->user->twoFactorQrCodeSvg() !!}
</div>

<div class="mt-4 max-w-xl text-sm text-gray-600">
<p class="font-semibold">
{{ __('Setup Key') }}: {{ decrypt($this->user->two_factor_secret) }}
</p>
</div>

@if ($showingConfirmation)
<div class="mt-4">
<x-jet-label for="code" value="{{ __('Code') }}" />
Expand Down