Files
TwoFactorAuth/lib/Providers/Qr/BaseHTTPQRCodeProvider.php
T
Nicolas CARPi 6f78141196 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
2024-05-07 03:08:31 +02:00

35 lines
902 B
PHP

<?php
declare(strict_types=1);
namespace RobThree\Auth\Providers\Qr;
use RobThree\Auth\TwoFactorAuthException;
abstract class BaseHTTPQRCodeProvider implements IQRCodeProvider
{
protected bool $verifyssl = true;
protected function getContent(string $url): string|bool
{
$curlhandle = curl_init();
curl_setopt_array($curlhandle, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_DNS_CACHE_TIMEOUT => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => $this->verifyssl,
CURLOPT_USERAGENT => 'TwoFactorAuth',
));
$data = curl_exec($curlhandle);
if ($data === false) {
throw new TwoFactorAuthException(curl_error($curlhandle));
}
curl_close($curlhandle);
return $data;
}
}