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 committed May 7, 2024
1 parent f5eb9a7 commit 6f78141
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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: 5 additions & 0 deletions lib/Providers/Qr/BaseHTTPQRCodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace RobThree\Auth\Providers\Qr;

use RobThree\Auth\TwoFactorAuthException;

abstract class BaseHTTPQRCodeProvider implements IQRCodeProvider
{
protected bool $verifyssl = true;
Expand All @@ -22,6 +24,9 @@ protected function getContent(string $url): string|bool
CURLOPT_USERAGENT => 'TwoFactorAuth',
));
$data = curl_exec($curlhandle);
if ($data === false) {
throw new TwoFactorAuthException(curl_error($curlhandle));
}

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

0 comments on commit 6f78141

Please sign in to comment.