From 6f781411964daba860233f21aef26bc6c823f71b Mon Sep 17 00:00:00 2001 From: Nicolas CARPi Date: Tue, 7 May 2024 03:08:31 +0200 Subject: [PATCH 1/2] handle curl errors. fix #129 if curl fails for some reason to get a QR code from an external (http) provider, the app will throw a TwoFactorAuthException. also fix the demo page with new constructor signature --- demo/demo.php | 2 +- lib/Providers/Qr/BaseHTTPQRCodeProvider.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/demo/demo.php b/demo/demo.php index 9139381..14abcfb 100644 --- a/demo/demo.php +++ b/demo/demo.php @@ -12,7 +12,7 @@ }); // substitute your company or app name here - $tfa = new RobThree\Auth\TwoFactorAuth('RobThree TwoFactorAuth'); + $tfa = new RobThree\Auth\TwoFactorAuth(new RobThree\Auth\Providers\Qr\QRServerProvider()); ?>
  • First create a secret and associate it with a user
  • 'TwoFactorAuth', )); $data = curl_exec($curlhandle); + if ($data === false) { + throw new TwoFactorAuthException(curl_error($curlhandle)); + } curl_close($curlhandle); return $data; From 6194bb08a78dd99c33d48d281784772952207cd3 Mon Sep 17 00:00:00 2001 From: Nicolas CARPi Date: Tue, 7 May 2024 03:16:01 +0200 Subject: [PATCH 2/2] throw a QRException instead and change the function signature --- lib/Providers/Qr/BaseHTTPQRCodeProvider.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Providers/Qr/BaseHTTPQRCodeProvider.php b/lib/Providers/Qr/BaseHTTPQRCodeProvider.php index fcd8744..fc43462 100644 --- a/lib/Providers/Qr/BaseHTTPQRCodeProvider.php +++ b/lib/Providers/Qr/BaseHTTPQRCodeProvider.php @@ -4,13 +4,11 @@ declare(strict_types=1); namespace RobThree\Auth\Providers\Qr; -use RobThree\Auth\TwoFactorAuthException; - abstract class BaseHTTPQRCodeProvider implements IQRCodeProvider { protected bool $verifyssl = true; - protected function getContent(string $url): string|bool + protected function getContent(string $url): string { $curlhandle = curl_init(); @@ -25,7 +23,7 @@ abstract class BaseHTTPQRCodeProvider implements IQRCodeProvider )); $data = curl_exec($curlhandle); if ($data === false) { - throw new TwoFactorAuthException(curl_error($curlhandle)); + throw new QRException(curl_error($curlhandle)); } curl_close($curlhandle);