Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
subrequests
Commits
f95bc1a7
Unverified
Commit
f95bc1a7
authored
Mar 24, 2017
by
Mateu Aguiló Bosch
Browse files
Fix authentication for subrequests
parent
257cb98b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Blueprint/RequestTree.php
View file @
f95bc1a7
...
...
@@ -293,6 +293,7 @@ class RequestTree {
(
array
)
$request
->
server
->
getIterator
(),
$content
);
// Set the sub-request headers.
foreach
(
$request
->
headers
as
$key
=>
$val
)
{
$new_request
->
headers
->
set
(
$key
,
$val
);
}
...
...
src/Controller/FrontController.php
View file @
f95bc1a7
...
...
@@ -68,7 +68,7 @@ class FrontController extends ControllerBase {
// Handle the requests for the trees at this level and gather the
// responses.
$level_responses
=
array_map
(
function
(
Request
$request
)
{
return
$this
->
httpKernel
->
handle
(
$request
,
HttpKernelInterface
::
SUB
_REQUEST
);
return
$this
->
httpKernel
->
handle
(
$request
,
HttpKernelInterface
::
MASTER
_REQUEST
);
},
$requests
);
$responses
=
array_merge
(
$responses
,
...
...
src/Normalizer/JsonSubrequestDenormalizer.php
View file @
f95bc1a7
...
...
@@ -55,6 +55,7 @@ class JsonSubrequestDenormalizer implements DenormalizerInterface {
$request
->
setSession
(
$master_request
->
getSession
());
// Replace the headers by the ones in the subrequest.
$request
->
headers
=
new
HeaderBag
(
$data
[
'headers'
]);
$this
::
fixBasicAuth
(
$request
);
// Add the content ID to the sub-request.
$content_id
=
empty
(
$data
[
'requestId'
])
...
...
@@ -116,4 +117,22 @@ class JsonSubrequestDenormalizer implements DenormalizerInterface {
}
}
/**
* Adds the decoded username and password headers for Basic Auth.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request to fix.
*/
protected
static
function
fixBasicAuth
(
Request
$request
)
{
// The server will not set the PHP_AUTH_USER and PHP_AUTH_PW for the
// subrequests if needed.
if
(
$request
->
headers
->
has
(
'Authorization'
))
{
$header
=
$request
->
headers
->
get
(
'Authorization'
);
if
(
strpos
(
$header
,
'Basic '
)
===
0
)
{
list
(
$user
,
$pass
)
=
explode
(
':'
,
base64_decode
(
substr
(
$header
,
6
)));
$request
->
headers
->
set
(
'PHP_AUTH_USER'
,
$user
);
$request
->
headers
->
set
(
'PHP_AUTH_PW'
,
$pass
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment