Skip to content

Commit df43660

Browse files
authored
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
2 parents f5eb9a7 + 6194bb0 commit df43660

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ abstract class BaseHTTPQRCodeProvider implements IQRCodeProvider
88
{
99
protected bool $verifyssl = true;
1010

11-
protected function getContent(string $url): string|bool
11+
protected function getContent(string $url): string
1212
{
1313
$curlhandle = curl_init();
1414

@@ -22,6 +22,9 @@ protected function getContent(string $url): string|bool
2222
CURLOPT_USERAGENT => 'TwoFactorAuth',
2323
));
2424
$data = curl_exec($curlhandle);
25+
if ($data === false) {
26+
throw new QRException(curl_error($curlhandle));
27+
}
2528

2629
curl_close($curlhandle);
2730
return $data;

0 commit comments

Comments
 (0)