|
2 年之前 | |
---|---|---|
.. | ||
src | 2 年之前 | |
CHANGELOG.md | 2 年之前 | |
LICENSE.md | 2 年之前 | |
README.md | 2 年之前 | |
composer.json | 2 年之前 | |
composer.lock | 2 年之前 |
This is package is Goole2FA integrated with a QRCode generator, providing an easy way to plot QRCode for your two factor authentication. For documentation related to Google2FA, please check the documentation of the main package.
Use Composer to install it:
composer require pragmarx/google2fa-qrcode
use PragmaRX\Google2FAQRCode\Google2FA;
$google2fa = new Google2FA();
return $google2fa->generateSecretKey();
The securer way of creating QRCode is to do it yourself or using a library. First you have to install the BaconQrCode package, as stated above, then you just have to generate the inline string using:
$inlineUrl = $google2fa->getQRCodeInline(
$companyName,
$companyEmail,
$secretKey
);
And use it in your blade template this way:
<img src="{{ $inlineUrl }}">
$secretKey = $google2fa->generateSecretKey(16, $userId);
It's insecure to use it via Google Apis, so you have to enable it before using it.
$google2fa->setAllowInsecureCallToGoogleApis(true);
$google2fa_url = $google2fa->getQRCodeGoogleUrl(
'YourCompany',
$user->email,
$user->google2fa_secret
);
/// and in your view:
<img src="{{ $google2fa_url }}" alt="">
And they should see and scan the QR code to their applications:
And to verify, you just have to:
$secret = $request->input('secret');
$valid = $google2fa->verifyKey($user->google2fa_secret, $secret);
The package tests were written with PHPUnit.
Google2FAQRCode is licensed under the MIT License - see the LICENSE file for details.
Pull requests and issues are more than welcome.