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

fix: fix login remember with 2fa and u2f enabled #1740

Merged
merged 5 commits into from Aug 26, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -139,6 +139,7 @@ v2.1.0 - 2018-05-03
* Support Arabic language
* Split app css in two files for better support of ltr/rtl text direction
* Add helper function htmldir()
* Fix login remember with 2fa and u2f enabled

v2.0.1 - 2018-04-17
-------------------
Expand Down
29 changes: 29 additions & 0 deletions app/Listeners/LoginListener.php
@@ -0,0 +1,29 @@
<?php

namespace App\Listeners;

use Illuminate\Auth\Events\Login;
use Lahaxearnaud\U2f\Models\U2fKey;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Auth\Validate2faController;

class LoginListener
{
/**
* Handle the Illuminate login event.
*
* @param Login $event
* @return void
*/
public function handle(Login $event)
{
if (Auth::viaRemember()) {
if (config('google2fa.enabled') && ! empty($event->user->google2fa_secret)) {
Validate2faController::loginCallback();
}
if (config('u2f.enable') && U2fKey::where('user_id', $event->user->getAuthIdentifier())->count() > 0) {
session([config('u2f.sessionU2fName') => true]);
}
}
}
}
17 changes: 5 additions & 12 deletions app/Listeners/LoginSucceed2fa.php
Expand Up @@ -2,28 +2,21 @@

namespace App\Listeners;

use Lahaxearnaud\U2f\Models\U2fKey;
use PragmaRX\Google2FALaravel\Events\LoginSucceeded;

class LoginSucceed2fa
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Handle the event.
* Handle the Login event of google2fa-laravel event.
*
* @param LoginSucceeded $event
* @return void
*/
public function handle(LoginSucceeded $event)
{
session([config('u2f.sessionU2fName') => true]);
if (config('u2f.enable') && U2fKey::where('user_id', $event->user->getAuthIdentifier())->count() > 0) {
session([config('u2f.sessionU2fName') => true]);
}
}
}
10 changes: 6 additions & 4 deletions app/Providers/EventServiceProvider.php
Expand Up @@ -17,6 +17,9 @@ class EventServiceProvider extends ServiceProvider
'PragmaRX\Google2FALaravel\Events\LoginSucceeded' => [
'App\Listeners\LoginSucceed2fa',
],
'Illuminate\Auth\Events\Login' => [
'App\Listeners\LoginListener',
],
];

/**
Expand All @@ -30,10 +33,9 @@ public function boot()
parent::boot();

Event::listen('u2f.authentication', function ($u2fKey, $user) {
Validate2faController::loginCallback();
});
Event::listen('LoginSucceeded', function ($u2fKey, $user) {
session([config('u2f.sessionU2fName') => true]);
if (config('google2fa.enabled') && ! empty($user->google2fa_secret)) {
Validate2faController::loginCallback();
}
});
}
}