mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-24 06:56:33 +00:00
6f78141196
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
35 lines
902 B
PHP
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;
|
|
}
|
|
}
|