TOTP integration

This commit is contained in:
Bubka
2019-05-26 16:42:09 +02:00
parent 482c01ca2c
commit 6a76a493a2
6 changed files with 374 additions and 5 deletions

View File

@@ -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.
*