|
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| src | ||
| composer.json | ||
| LICENSE.md | ||
| phpstan.neon.dist | ||
| README.md | ||
Google2FA QRCode
QRCode For Google2FA
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.
Version Compatibility
| PHP | pragmarx/google2fa-qrcode |
|---|---|
7.1 |
3.x |
7.2 |
3.x |
7.3 |
3.x |
7.4 |
3.x |
8.0 |
3.x |
8.1 |
4.x |
8.2 |
4.x |
8.3 |
4.x |
8.4 |
4.x |
8.5 |
4.x |
Installing
Use Composer to install it:
composer require pragmarx/google2fa-qrcode
Using It
Instantiate it directly
use PragmaRX\Google2FAQRCode\Google2FA;
$google2fa = new Google2FA();
return $google2fa->generateSecretKey();
Generating QRCodes
The securer way of creating QRCode is to do it yourself or using a library. First you have to install the Chillerlan or BaconQrCode package, 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);
Show the QR Code to your user, via Google Apis
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);
Replacing the QRCode rendering service
If you want to use a different service, you just have to
$google2fa->setQRCodeService(new YourService())
->getQRCodeInline(
$companyName,
$companyEmail,
$secretKey
);
Built-in QRCode rendering services
Beginning on version 2.0 the rendering service is optional, so you have to manually install one of those packages in order to generate QRCodes:
- BaconQrCode: renders PNG by default, but requires the Imagick PHP extension. You can configure it to use different backends, but you'll have to instantiate it yourself.
- chillerlan/php-qrcode: renders SVG by default and don't require the Imagick PHP extension, but can also generate other formats, which may require Imagick.
Using a different image backend
$google2fa->setQRCodeService(
new \PragmaRX\Google2FAQRCode\QRCode\Bacon(
new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
)
);
// or
$google2fa = new Google2FA(
new Bacon(
new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
)
);
Tests
The package tests were written with PHPUnit.
Authors
License
Google2FAQRCode is licensed under the MIT License - see the LICENSE file for details.
Contributing
Pull requests and issues are more than welcome.