Skip to content

Commit 6f78141

Browse files
committed
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
1 parent f5eb9a7 commit 6f78141

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

demo/demo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
});
1313

1414
// substitute your company or app name here
15-
$tfa = new RobThree\Auth\TwoFactorAuth('RobThree TwoFactorAuth');
15+
$tfa = new RobThree\Auth\TwoFactorAuth(new RobThree\Auth\Providers\Qr\QRServerProvider());
1616
?>
1717
<li>First create a secret and associate it with a user</li>
1818
<?php

lib/Providers/Qr/BaseHTTPQRCodeProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace RobThree\Auth\Providers\Qr;
66

7+
use RobThree\Auth\TwoFactorAuthException;
8+
79
abstract class BaseHTTPQRCodeProvider implements IQRCodeProvider
810
{
911
protected bool $verifyssl = true;
@@ -22,6 +24,9 @@ protected function getContent(string $url): string|bool
2224
CURLOPT_USERAGENT => 'TwoFactorAuth',
2325
));
2426
$data = curl_exec($curlhandle);
27+
if ($data === false) {
28+
throw new TwoFactorAuthException(curl_error($curlhandle));
29+
}
2530

2631
curl_close($curlhandle);
2732
return $data;

0 commit comments

Comments
 (0)