From 0ab012bbaf5d4746ea4ddff7ce0ca12020d81cdd Mon Sep 17 00:00:00 2001 From: Nicolas CARPi Date: Tue, 20 Aug 2024 13:35:17 +0200 Subject: [PATCH 1/2] remove warning about default external qr code provider in README.md In version 3.0, the qrcode provider must be explicitely set, so the warning is not needed anymore. Also rewrite the part about the curl library for php. --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index a4c7a42..765e4ec 100644 --- a/README.md +++ b/README.md @@ -8,23 +8,16 @@ PHP library for [two-factor (or multi-factor) authentication](http://en.wikipedi

-## Warning: - -By default, this package uses the `lib/Providers/QRServerProvider.php` as QR code generator. This provider is __not__ suggested for applications where absolute security is needed, because it uses an external service for the QR code generation. - - -You can make use of the included [Endroid](https://robthree.github.io/TwoFactorAuth/qr-codes/endroid.html) or [Bacon](https://robthree.github.io/TwoFactorAuth/qr-codes/bacon.html) providers which generate locally. - ## Requirements * Requires PHP version >=8.2 -* [cURL](http://php.net/manual/en/book.curl.php) when using the provided `QRServerProvider` (default), `ImageChartsQRCodeProvider` or `QRicketProvider` but you can also provide your own QR-code provider. Optionally, you may need: * [sockets](https://www.php.net/manual/en/book.sockets.php) if you are using `NTPTimeProvider` * [endroid/qr-code](https://github.com/endroid/qr-code) if using `EndroidQrCodeProvider` or `EndroidQrCodeWithLogoProvider`. * [bacon/bacon-qr-code](https://github.com/Bacon/BaconQrCode) if using `BaconQrCodeProvider`. +* [php-curl library](http://php.net/manual/en/book.curl.php) when using an external QR Code provider such as `QRServerProvider`, `ImageChartsQRCodeProvider`, `QRicketProvider` or any other custom provider connecting to an external service. ## Installation From 92487acba4135f1c110149a233f7b17a4b855eb7 Mon Sep 17 00:00:00 2001 From: cliffordvickrey Date: Thu, 24 Oct 2024 08:01:17 -0400 Subject: [PATCH 2/2] add support for endroid/qr-code version 6 (#140) * add support for endroid/qr-code version 6 * add endroid v6 to github workflows * remove negative conditional (endroid-related) --------- Co-authored-by: Clifford Vickrey --- .github/workflows/test-endroid.yml | 2 +- lib/Providers/Qr/EndroidQrCodeProvider.php | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-endroid.yml b/.github/workflows/test-endroid.yml index 72b17bc..169f77b 100644 --- a/.github/workflows/test-endroid.yml +++ b/.github/workflows/test-endroid.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: php-version: ['8.2', '8.3'] - endroid-version: ["^3","^4","^5"] + endroid-version: ["^3","^4","^5","^6"] steps: - uses: actions/checkout@v4 diff --git a/lib/Providers/Qr/EndroidQrCodeProvider.php b/lib/Providers/Qr/EndroidQrCodeProvider.php index 4d42c18..a544cb6 100755 --- a/lib/Providers/Qr/EndroidQrCodeProvider.php +++ b/lib/Providers/Qr/EndroidQrCodeProvider.php @@ -28,10 +28,13 @@ class EndroidQrCodeProvider implements IQRCodeProvider protected $endroid5 = false; + protected $endroid6 = false; + public function __construct($bgcolor = 'ffffff', $color = '000000', $margin = 0, $errorcorrectionlevel = 'H') { - $this->endroid4 = method_exists(QrCode::class, 'create'); $this->endroid5 = enum_exists(ErrorCorrectionLevel::class); + $this->endroid6 = $this->endroid5 && !method_exists(QrCode::class, 'setSize'); + $this->endroid4 = $this->endroid6 || method_exists(QrCode::class, 'create'); $this->bgcolor = $this->handleColor($bgcolor); $this->color = $this->handleColor($color); @@ -56,6 +59,17 @@ public function getQRCodeImage(string $qrText, int $size): string protected function qrCodeInstance(string $qrText, int $size): QrCode { + if ($this->endroid6) { + return new QrCode( + data: $qrText, + errorCorrectionLevel: $this->errorcorrectionlevel, + size: $size, + margin: $this->margin, + foregroundColor: $this->color, + backgroundColor: $this->bgcolor + ); + } + $qrCode = new QrCode($qrText); $qrCode->setSize($size); @@ -63,7 +77,6 @@ protected function qrCodeInstance(string $qrText, int $size): QrCode $qrCode->setMargin($this->margin); $qrCode->setBackgroundColor($this->bgcolor); $qrCode->setForegroundColor($this->color); - return $qrCode; }