Skip to content

Commit 4fe3ead

Browse files
dzubchikmarcj
authored andcommitted
Handle php native authorization headers (#46)
1 parent 4754a51 commit 4fe3ead

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Bridges/HttpKernel.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ protected function mapRequest(ReactRequest $reactRequest)
150150
session_id(Utils::generateSessionId());
151151
}
152152

153+
$_SERVER['PHP_AUTH_USER'] = '';
154+
$_SERVER['PHP_AUTH_PW'] = '';
155+
$_SERVER['AUTH_TYPE'] = '';
156+
157+
if (isset($headers['Authorization'])) {
158+
$authorizationHeader = $headers['Authorization'];
159+
$authorizationHeaderParts = explode(' ', $authorizationHeader);
160+
$type = $authorizationHeaderParts[0];
161+
if (($type === 'Basic' || $type === 'Digest') && isset($authorizationHeaderParts[1])) {
162+
$credentials = base64_decode($authorizationHeaderParts[1]);
163+
$credentialsParts = explode(':', $credentials);
164+
$_SERVER['PHP_AUTH_USER'] = isset($credentialsParts[0]) ? $credentialsParts[0] : '';
165+
$_SERVER['PHP_AUTH_PW'] = isset($credentialsParts[1]) ? $credentialsParts[1] : '';
166+
$_SERVER['AUTH_TYPE'] = $type;
167+
}
168+
}
169+
153170
$files = $reactRequest->getFiles();
154171
$post = $reactRequest->getPost();
155172

@@ -163,7 +180,7 @@ protected function mapRequest(ReactRequest $reactRequest)
163180
$syRequest = new $class($query, $post, $attributes = [], $cookies, $files, $_SERVER, $reactRequest->getBody());
164181

165182
$syRequest->setMethod($method);
166-
$syRequest->headers->replace($headers);
183+
$syRequest->headers->add($headers);
167184

168185
return $syRequest;
169186
}

0 commit comments

Comments
 (0)