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
This commit is contained in:
Nicolas CARPi
2024-05-07 03:08:31 +02:00
parent f5eb9a7051
commit 6f78141196
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -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());
?>
<li>First create a secret and associate it with a user</li>
<?php
@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace RobThree\Auth\Providers\Qr;
use RobThree\Auth\TwoFactorAuthException;
abstract class BaseHTTPQRCodeProvider implements IQRCodeProvider
{
protected bool $verifyssl = true;
@@ -22,6 +24,9 @@ abstract class BaseHTTPQRCodeProvider implements IQRCodeProvider
CURLOPT_USERAGENT => 'TwoFactorAuth',
));
$data = curl_exec($curlhandle);
if ($data === false) {
throw new TwoFactorAuthException(curl_error($curlhandle));
}
curl_close($curlhandle);
return $data;