File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515use Psr \Log \LoggerInterface ;
1616use Sylius \Component \Channel \Context \ChannelContextInterface ;
1717use Symfony \Component \HttpFoundation \Request ;
18+ use Symfony \Component \HttpFoundation \Response ;
1819
1920final class RequestAuthenticator implements RequestAuthenticatorInterface
2021{
@@ -39,6 +40,14 @@ public function authenticate(Request $request): bool
3940
4041 $ content = $ request ->getContent (false );
4142
43+ if (is_resource ($ content )) {
44+ $ content = stream_get_contents ($ content );
45+ }
46+
47+ if (false === $ content ) {
48+ throw new \InvalidArgumentException ('Invalid JSON payload ' , Response::HTTP_BAD_REQUEST );
49+ }
50+
4251 $ content = json_encode (
4352 json_decode ($ content , true ),
4453 \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE ,
Original file line number Diff line number Diff line change @@ -36,7 +36,17 @@ public function __invoke(Request $request): Response
3636 if (false === $ this ->requestAuthenticator ->authenticate ($ request )) {
3737 return new JsonResponse ('Unauthorized ' , Response::HTTP_UNAUTHORIZED );
3838 }
39- $ payload = json_decode ($ request ->getContent (false ), true );
39+
40+ $ payload = $ request ->getContent (false );
41+ if (is_resource ($ payload )) {
42+ $ payload = stream_get_contents ($ payload );
43+ }
44+
45+ if (false === $ payload ) {
46+ return new JsonResponse ('Invalid JSON payload ' , Response::HTTP_BAD_REQUEST );
47+ }
48+
49+ $ payload = json_decode ($ payload , true );
4050
4151 if (!is_array ($ payload ) || [] === $ payload ) {
4252 return new JsonResponse ('Invalid JSON payload ' , Response::HTTP_BAD_REQUEST );
You can’t perform that action at this time.
0 commit comments