fix(auth): extend stream-based HTTP to POST requests in OidcHttpGateway
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,32 +11,41 @@ class OidcHttpGateway
|
||||
*/
|
||||
public function call(string $method, string $url, mixed $data = '', array $headers = []): array
|
||||
{
|
||||
if (strtoupper($method) === 'GET') {
|
||||
return $this->getWithStream($url, $headers);
|
||||
}
|
||||
return Curl::call($method, $url, $data, $headers);
|
||||
return $this->callWithStream(strtoupper($method), $url, $data, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $headers
|
||||
*/
|
||||
private function getWithStream(string $url, array $headers): array
|
||||
private function callWithStream(string $method, string $url, mixed $data, array $headers): array
|
||||
{
|
||||
$headerLines = [];
|
||||
foreach ($headers as $key => $value) {
|
||||
$headerLines[] = $key . ': ' . $value;
|
||||
}
|
||||
|
||||
$httpContext = [
|
||||
'method' => $method,
|
||||
'header' => implode("\r\n", $headerLines),
|
||||
'ignore_errors' => true,
|
||||
];
|
||||
|
||||
if ($method === 'POST') {
|
||||
$body = is_array($data) ? http_build_query($data) : (string) $data;
|
||||
$httpContext['content'] = $body;
|
||||
if (!isset($headers['Content-Type'])) {
|
||||
$httpContext['header'] .= "\r\nContent-Type: application/x-www-form-urlencoded";
|
||||
}
|
||||
}
|
||||
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'header' => implode("\r\n", $headerLines),
|
||||
'ignore_errors' => true,
|
||||
],
|
||||
'http' => $httpContext,
|
||||
'ssl' => [
|
||||
'verify_peer' => true,
|
||||
'verify_peer_name' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
$status = 0;
|
||||
$responseHeaders = [];
|
||||
|
||||
Reference in New Issue
Block a user