Changeset View
Changeset View
Standalone View
Standalone View
src/app/Auth/SecondFactor.php
<?php | <?php | ||||
namespace App\Auth; | namespace App\Auth; | ||||
use App\Sku; | |||||
use App\User; | |||||
use Illuminate\Support\Facades\Auth; | use Illuminate\Support\Facades\Auth; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
use Kolab2FA\Storage\Base; | use Kolab2FA\Storage\Base; | ||||
/** | /** | ||||
* A class to maintain 2-factor authentication | * A class to maintain 2-factor authentication | ||||
*/ | */ | ||||
class SecondFactor extends Base | class SecondFactor extends Base | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | class SecondFactor extends Base | ||||
} | } | ||||
/** | /** | ||||
* Returns a list of 2nd factor methods configured for the user | * Returns a list of 2nd factor methods configured for the user | ||||
*/ | */ | ||||
public function factors(): array | public function factors(): array | ||||
{ | { | ||||
// First check if the user has the 2FA SKU | // First check if the user has the 2FA SKU | ||||
$sku_2fa = Sku::where('title', '2fa')->first(); | if ($this->user->hasSku('2fa')) { | ||||
if ($sku_2fa) { | |||||
$has_2fa = $this->user->entitlements()->where('sku_id', $sku_2fa->id)->first(); | |||||
if ($has_2fa) { | |||||
$factors = (array) $this->enumerate(); | $factors = (array) $this->enumerate(); | ||||
$factors = array_unique($factors); | $factors = array_unique($factors); | ||||
return $factors; | return $factors; | ||||
} | } | ||||
} | |||||
return []; | return []; | ||||
} | } | ||||
/** | /** | ||||
* Helper method to verify the given method/code tuple | * Helper method to verify the given method/code tuple | ||||
* | * | ||||
* @param string $factor Factor identifier (<method>:<id>) | * @param string $factor Factor identifier (<method>:<id>) | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | class SecondFactor extends Base | ||||
* Helper for generating current TOTP code for a test user | * Helper for generating current TOTP code for a test user | ||||
* | * | ||||
* @param string $email Email address | * @param string $email Email address | ||||
* | * | ||||
* @return string Generated code | * @return string Generated code | ||||
*/ | */ | ||||
public static function code(string $email): string | public static function code(string $email): string | ||||
{ | { | ||||
$sf = new self(User::where('email', $email)->first()); | $sf = new self(\App\User::where('email', $email)->first()); | ||||
$driver = $sf->getDriver('totp:8132a46b1f741f88de25f47e'); | $driver = $sf->getDriver('totp:8132a46b1f741f88de25f47e'); | ||||
return (string) $driver->get_code(); | return (string) $driver->get_code(); | ||||
} | } | ||||
//****************************************************** | //****************************************************** | ||||
// Methods required by Kolab2FA Storage Base | // Methods required by Kolab2FA Storage Base | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |