has(static::TOTP_SETUP_SECRET_SESSION_KEY)) { $totpSecret = decrypt(session()->get(static::TOTP_SETUP_SECRET_SESSION_KEY)); } else { $totpSecret = $google2fa->generateSecretKey(); session()->put(static::TOTP_SETUP_SECRET_SESSION_KEY, encrypt($totpSecret)); } $qrCodeUrl = $google2fa->getQRCodeUrl( setting('app-name'), user()->email, $totpSecret ); $color = Fill::uniformColor(new Rgb(255, 255, 255), new Rgb(32, 110, 167)); $svg = (new Writer( new ImageRenderer( new RendererStyle(192, 0, null, null, $color), new SvgImageBackEnd ) ))->writeString($qrCodeUrl); // Get user to verify setup via responding once. // If correct response, Save key against user return view('mfa.totp-generate', [ 'secret' => $totpSecret, 'svg' => $svg, ]); } /** * Confirm the setup of TOTP and save the auth method secret * against the current user. * @throws ValidationException */ public function totpConfirm(Request $request) { $this->validate($request, [ 'code' => 'required|max:12|min:4' ]); // TODO - Confirm code dd($request->input('code')); } }