mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-18 09:29:46 +02:00
TOTP integration
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\TwoFAccount;
|
||||
use OTPHP\TOTP;
|
||||
use OTPHP\Factory;
|
||||
use Illuminate\Http\Request;
|
||||
use ParagonIE\ConstantTime\Base32;
|
||||
|
||||
class TwoFAccountController extends Controller
|
||||
{
|
||||
@@ -47,6 +50,29 @@ class TwoFAccountController extends Controller
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a TOTP
|
||||
*
|
||||
* @param \App\TwoFAccount $twofaccount
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function generateTOTP(TwoFAccount $twofaccount)
|
||||
{
|
||||
try {
|
||||
$otp = Factory::loadFromProvisioningUri($twofaccount->secret);
|
||||
} catch (InvalidArgumentException $exception) {
|
||||
return response()->json([
|
||||
'message' => 'Error generating TOTP',
|
||||
], 500);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'totp' => $otp->now(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
|
Reference in New Issue
Block a user