Skip to content

2FA setup key #371

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

Merged
merged 4 commits into from
Mar 25, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions routes/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Laravel\Fortify\Http\Controllers\TwoFactorAuthenticatedSessionController;
use Laravel\Fortify\Http\Controllers\TwoFactorAuthenticationController;
use Laravel\Fortify\Http\Controllers\TwoFactorQrCodeController;
use Laravel\Fortify\Http\Controllers\TwoFactorSetupKeyController;
use Laravel\Fortify\Http\Controllers\VerifyEmailController;

Route::group(['middleware' => config('fortify.middleware', ['web'])], function () {
Expand Down Expand Up @@ -154,6 +155,10 @@
->middleware($twoFactorMiddleware)
->name('two-factor.qr-code');

Route::get('/user/two-factor-setup-key', [TwoFactorSetupKeyController::class, 'show'])
->middleware($twoFactorMiddleware)
->name('two-factor.setup-key');

Route::get('/user/two-factor-recovery-codes', [RecoveryCodeController::class, 'index'])
->middleware($twoFactorMiddleware)
->name('two-factor.recovery-codes');
Expand Down
26 changes: 26 additions & 0 deletions src/Http/Controllers/TwoFactorSetupKeyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Laravel\Fortify\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

class TwoFactorSetupKeyController extends Controller
{
/**
* Get the current user's two factor authentication setup key.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function show(Request $request)
{
if (is_null($request->user()->two_factor_secret)) {
abort(404, 'Two factor authentication has not been enabled.');
}

return response()->json([
'setupKey' => decrypt($request->user()->two_factor_secret),
]);
}
}