mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 14:58:40 +00:00
Enable the creation of a MFA token in users auth app, and store the MFA secret in profile.
This commit is contained in:
@@ -45,6 +45,8 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Laravel\Passport\ClientRepository;
|
use Laravel\Passport\ClientRepository;
|
||||||
use Log;
|
use Log;
|
||||||
|
use PragmaRX\Recovery\Recovery;
|
||||||
|
use Preferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ProfileController.
|
* Class ProfileController.
|
||||||
@@ -140,9 +142,20 @@ class ProfileController extends Controller
|
|||||||
$secret = Google2FA::generateSecretKey();
|
$secret = Google2FA::generateSecretKey();
|
||||||
session()->flash('two-factor-secret', $secret);
|
session()->flash('two-factor-secret', $secret);
|
||||||
|
|
||||||
|
// generate recovery codes:
|
||||||
|
$recovery = app( Recovery::class);
|
||||||
|
$recoveryCodes =$recovery->lowercase()
|
||||||
|
->setCount(8) // Generate 8 codes
|
||||||
|
->setBlocks(2) // Every code must have 7 blocks
|
||||||
|
->setChars(6) // Each block must have 16 chars
|
||||||
|
->toArray();
|
||||||
|
$codes = implode("\r\n", $recoveryCodes);
|
||||||
|
|
||||||
|
Preferences::set('mfa_recovery', $recoveryCodes);
|
||||||
|
|
||||||
$image = Google2FA::getQRCodeInline($domain, auth()->user()->email, $secret);
|
$image = Google2FA::getQRCodeInline($domain, auth()->user()->email, $secret);
|
||||||
|
|
||||||
return view('profile.code', compact('image', 'secret'));
|
return view('profile.code', compact('image', 'secret','codes'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -234,18 +247,18 @@ class ProfileController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function enable2FA()
|
public function enable2FA()
|
||||||
{
|
{
|
||||||
die('this method is deprecated.');
|
/** @var User $user */
|
||||||
$hasSecret = (null !== app('preferences')->get('twoFactorAuthSecret'));
|
$user = auth()->user();
|
||||||
|
$enabledMFA = null !== $user->mfa_secret;
|
||||||
|
|
||||||
// if we don't have a valid secret yet, redirect to the code page to get one.
|
// if we don't have a valid secret yet, redirect to the code page to get one.
|
||||||
if (!$hasSecret) {
|
if (!$enabledMFA) {
|
||||||
return redirect(route('profile.code'));
|
return redirect(route('profile.code'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If FF3 already has a secret, just set the two factor auth enabled to 1,
|
// If FF3 already has a secret, just set the two factor auth enabled to 1,
|
||||||
// and let the user continue with the existing secret.
|
// and let the user continue with the existing secret.
|
||||||
|
session()->flash('info', (string)trans('firefly.2fa_already_enabled'));
|
||||||
app('preferences')->set('twoFactorAuthEnabled', 1);
|
|
||||||
|
|
||||||
return redirect(route('profile.index'));
|
return redirect(route('profile.index'));
|
||||||
}
|
}
|
||||||
@@ -388,9 +401,14 @@ class ProfileController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function postCode(TokenFormRequest $request)
|
public function postCode(TokenFormRequest $request)
|
||||||
{
|
{
|
||||||
die('this method is deprecated');
|
/** @var User $user */
|
||||||
app('preferences')->set('twoFactorAuthEnabled', 1);
|
$user = auth()->user();
|
||||||
app('preferences')->set('twoFactorAuthSecret', session()->get('two-factor-secret'));
|
/** @var UserRepositoryInterface $repository */
|
||||||
|
$repository = app(UserRepositoryInterface::class);
|
||||||
|
/** @var string $secret */
|
||||||
|
$secret = session()->get('two-factor-secret');
|
||||||
|
|
||||||
|
$repository->setMFACode($user, $secret);
|
||||||
|
|
||||||
session()->flash('success', (string)trans('firefly.saved_preferences'));
|
session()->flash('success', (string)trans('firefly.saved_preferences'));
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
|
@@ -486,7 +486,7 @@ return [
|
|||||||
'pref_two_factor_auth_code_help' => 'Scan the QR code with an application on your phone such as Authy or Google Authenticator and enter the generated code.',
|
'pref_two_factor_auth_code_help' => 'Scan the QR code with an application on your phone such as Authy or Google Authenticator and enter the generated code.',
|
||||||
'pref_two_factor_auth_reset_code' => 'Reset verification code',
|
'pref_two_factor_auth_reset_code' => 'Reset verification code',
|
||||||
'pref_two_factor_auth_disable_2fa' => 'Disable 2FA',
|
'pref_two_factor_auth_disable_2fa' => 'Disable 2FA',
|
||||||
'2fa_use_secret_instead' => 'If you cannot scan the QR code, feel free to use the secret instead: :secret.',
|
'2fa_use_secret_instead' => 'If you cannot scan the QR code, feel free to use the secret instead: <code>:secret</code>.',
|
||||||
'2fa_backup_codes' => 'Store these backup codes for access in case you lose your device.',
|
'2fa_backup_codes' => 'Store these backup codes for access in case you lose your device.',
|
||||||
'2fa_already_enabled' => '2-step verification is already enabled.',
|
'2fa_already_enabled' => '2-step verification is already enabled.',
|
||||||
'pref_save_settings' => 'Save settings',
|
'pref_save_settings' => 'Save settings',
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
<form method="POST" action="{{ route('profile.code.store') }}" accept-charset="UTF-8" class="form-horizontal" id="preferences_code">
|
<form method="POST" action="{{ route('profile.code.store') }}" accept-charset="UTF-8" class="form-horizontal" id="preferences_code">
|
||||||
<input name="_token" type="hidden" value="{{ csrf_token() }}">
|
<input name="_token" type="hidden" value="{{ csrf_token() }}">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12 col-xs-12">
|
<div class="col-lg-6 col-lg-offset-3 col-md-12 col-sm-12 col-xs-12">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'pref_two_factor_auth_code'|_ }}</h3>
|
<h3 class="box-title">{{ 'pref_two_factor_auth_code'|_ }}</h3>
|
||||||
@@ -23,15 +23,19 @@
|
|||||||
style="border:1px #ddd solid;"/>
|
style="border:1px #ddd solid;"/>
|
||||||
</div>
|
</div>
|
||||||
<p>
|
<p>
|
||||||
{{ trans('firefly.2fa_use_secret_instead', {secret: secret}) }}
|
{{ trans('firefly.2fa_use_secret_instead', {secret: secret|escape})|raw }}
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
{{ '2fa_backup_codes'|_ }}
|
||||||
|
</p>
|
||||||
|
<pre>{{ codes }}</pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12 col-xs-12">
|
<div class="col-lg-6 col-lg-offset-3 col-md-12 col-sm-12 col-xs-12">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
{{ ExpandedForm.text('code', code) }}
|
{{ ExpandedForm.text('code', code) }}
|
||||||
|
Reference in New Issue
Block a user