pragmarx/google2fa-qrcode
Composer 安装命令:
composer require pragmarx/google2fa-qrcode
包简介
QR Code package for Google2FA
README 文档
README
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.
pragmarx/google2fa-qrcode 适用场景与选型建议
pragmarx/google2fa-qrcode 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32.79M 次下载、GitHub Stars 达 121, 最近一次更新时间为 2018 年 10 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Authentication」 「qr code」 「qrcode」 「2fa」 「Two Factor Authentication」 「google2fa」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pragmarx/google2fa-qrcode 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pragmarx/google2fa-qrcode 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pragmarx/google2fa-qrcode 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Based in http://phpqrcode.sourceforge.net/
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
Symfony 4, 5, 6 ,7 Barcode Generator Bundle with Twig function extension
GraphQL authentication for your headless Craft CMS applications.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
统计信息
- 总下载量: 32.79M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 125
- 点击次数: 55
- 依赖项目数: 39
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-07