You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use PragmaRX\Google2FALaravel\Facade as Google2FA;
class TwoFactorController extends Controller
{
public function show()
{
return view('auth.google2fa.show'); // Use the appropriate view for your 2FA verification page
}
public function verify(Request $request)
{
$validated = $request->validate([
'one_time_password' => 'required',
]);
$user = Auth::user();
$google2fa = app('pragmarx.google2fa');
$valid = $google2fa->verifyKey($user->google2fa_secret, $request->input('one_time_password'));
// Verify the 2FA code using the package's functionality
if ($valid) {
// 2FA code is valid, proceed with login
return redirect()->route('admin.dashboard');
} else {
// Invalid 2FA code, redirect back with an error message
return redirect()->route('2fa')->withErrors(['one_time_password' => 'Invalid OTP code']);
}
}
}
Config google2fa.php:
<?php
return [
/*
* Enable / disable Google2FA.
*/
'enabled' => env('OTP_ENABLED', true),
/*
* Lifetime in minutes.
*
* In case you need your users to be asked for a new one time passwords from time to time.
*/
'lifetime' => env('OTP_LIFETIME', 0), // 0 = eternal
/*
* Renew lifetime at every new request.
*/
'keep_alive' => env('OTP_KEEP_ALIVE', true),
/*
* Auth container binding.
*/
'auth' => 'auth',
/*
* Guard.
*/
'guard' => '',
/*
* 2FA verified session var.
*/
'session_var' => 'google2fa',
/*
* One Time Password request input name.
*/
'otp_input' => 'one_time_password',
/*
* One Time Password Window.
*/
'window' => 1,
/*
* Forbid user to reuse One Time Passwords.
*/
'forbid_old_passwords' => false,
/*
* User's table column for google2fa secret.
*/
'otp_secret_column' => 'google2fa_secret',
/*
* One Time Password View.
*/
'view' => 'auth.google2fa.show',
/*
* One Time Password error message.
*/
'error_messages' => [
'wrong_otp' => "The 'One Time Password' typed was wrong.",
'cannot_be_empty' => 'One Time Password cannot be empty.',
'unknown' => 'An unknown error has occurred. Please try again.',
],
/*
* Throw exceptions or just fire events?
*/
'throw_exceptions' => env('OTP_THROW_EXCEPTION', true),
/*
* Which image backend to use for generating QR codes?
*
* Supports imagemagick, svg and eps
*/
'qrcode_image_backend' => \PragmaRX\Google2FALaravel\Support\Constants::QRCODE_IMAGE_BACKEND_SVG,
];
While the flow and logic works fine up until the verification OTP, when I enter a valid OTP, it verifies successfully but it does not redirect to the home dashboard. It just redirects back to the OTP page. I assumed is because it somehow did not "pass" the 2fa middleware in my routes. I am not sure why is this the case or if I am missing something as i could not find a solution online for my issue.
Does anyone know the issue?
The text was updated successfully, but these errors were encountered:
I want to implement google authenticator to my app so after user logins, they will be prompt to enter the TOTP.
So far, I have followed the package documentation and install it as well as setting up the middleware,etc.
Here is my login method:
My auth.google2fa.show.blade.php:
TwoFactorController.php :
Config google2fa.php:
web.php:
While the flow and logic works fine up until the verification OTP, when I enter a valid OTP, it verifies successfully but it does not redirect to the home dashboard. It just redirects back to the OTP page. I assumed is because it somehow did not "pass" the 2fa middleware in my routes. I am not sure why is this the case or if I am missing something as i could not find a solution online for my issue.
Does anyone know the issue?
The text was updated successfully, but these errors were encountered: