@@ -318,24 +318,30 @@ private function removeTokenInRequest(RequestInterface $request): void
318318 {
319319 assert ($ request instanceof Request);
320320
321- $ json = json_decode ($ request ->getBody () ?? '' );
322-
323321 if (isset ($ _POST [$ this ->config ->tokenName ])) {
324322 // We kill this since we're done and we don't want to pollute the POST array.
325323 unset($ _POST [$ this ->config ->tokenName ]);
326324 $ request ->setGlobal ('post ' , $ _POST );
327- } elseif (isset ($ json ->{$ this ->config ->tokenName })) {
328- // We kill this since we're done and we don't want to pollute the JSON data.
329- unset($ json ->{$ this ->config ->tokenName });
330- $ request ->setBody (json_encode ($ json ));
325+ } else {
326+ $ body = $ request ->getBody () ?? '' ;
327+ if (! empty ($ json = json_decode ($ body )) && json_last_error () === JSON_ERROR_NONE ) {
328+ // We kill this since we're done and we don't want to pollute the JSON data.
329+ unset($ json ->{$ this ->config ->tokenName });
330+ $ request ->setBody (json_encode ($ json ));
331+ } else {
332+ parse_str ($ body , $ parsed );
333+ // We kill this since we're done and we don't want to pollute the BODY data.
334+ unset($ parsed [$ this ->config ->tokenName ]);
335+ $ request ->setBody (http_build_query ($ parsed ));
336+ }
331337 }
332338 }
333339
334340 private function getPostedToken (RequestInterface $ request ): ?string
335341 {
336342 assert ($ request instanceof IncomingRequest);
337343
338- // Does the token exist in POST, HEADER or optionally php:://input - json data.
344+ // Does the token exist in POST, HEADER or optionally php:://input - json data or PUT, DELETE, PATCH - raw data .
339345
340346 if ($ tokenValue = $ request ->getPost ($ this ->config ->tokenName )) {
341347 return $ tokenValue ;
@@ -346,10 +352,15 @@ private function getPostedToken(RequestInterface $request): ?string
346352 }
347353
348354 $ body = (string ) $ request ->getBody ();
349- $ json = json_decode ($ body );
350355
351- if ($ body !== '' && ! empty ($ json ) && json_last_error () === JSON_ERROR_NONE ) {
352- return $ json ->{$ this ->config ->tokenName } ?? null ;
356+ if ($ body !== '' ) {
357+ if (! empty ($ json = json_decode ($ body )) && json_last_error () === JSON_ERROR_NONE ) {
358+ return $ json ->{$ this ->config ->tokenName } ?? null ;
359+ }
360+
361+ parse_str ($ body , $ parsed );
362+
363+ return $ parsed [$ this ->config ->tokenName ] ?? null ;
353364 }
354365
355366 return null ;
0 commit comments