Skip to content

Commit

Permalink
handle curl errors. fix #129
Browse files Browse the repository at this point in the history
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
  • Loading branch information
NicolasCARPi authored May 7, 2024
2 parents f5eb9a7 + 6194bb0 commit df43660
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion demo/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/Providers/Qr/BaseHTTPQRCodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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();

Expand All @@ -22,6 +22,9 @@ protected function getContent(string $url): string|bool
CURLOPT_USERAGENT => 'TwoFactorAuth',
));
$data = curl_exec($curlhandle);
if ($data === false) {
throw new QRException(curl_error($curlhandle));
}

curl_close($curlhandle);
return $data;
Expand Down

0 comments on commit df43660

Please sign in to comment.