Skip to content

Commit a6a7b9b

Browse files
authored
Merge pull request #7377 from kenjis/refactor-getPostedToken
refactor: Security::getPostedToken()
2 parents f6bf798 + c3d8020 commit a6a7b9b

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

system/Security/Security.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,23 @@ private function getPostedToken(RequestInterface $request): ?string
342342
assert($request instanceof IncomingRequest);
343343

344344
// Does the token exist in POST, HEADER or optionally php:://input - json data.
345+
346+
if ($tokenValue = $request->getPost($this->tokenName)) {
347+
return $tokenValue;
348+
}
349+
345350
if ($request->hasHeader($this->headerName) && ! empty($request->header($this->headerName)->getValue())) {
346-
$tokenName = $request->header($this->headerName)->getValue();
347-
} else {
348-
$body = (string) $request->getBody();
349-
$json = json_decode($body);
351+
return $request->header($this->headerName)->getValue();
352+
}
350353

351-
if ($body !== '' && ! empty($json) && json_last_error() === JSON_ERROR_NONE) {
352-
$tokenName = $json->{$this->tokenName} ?? null;
353-
} else {
354-
$tokenName = null;
355-
}
354+
$body = (string) $request->getBody();
355+
$json = json_decode($body);
356+
357+
if ($body !== '' && ! empty($json) && json_last_error() === JSON_ERROR_NONE) {
358+
return $json->{$this->tokenName} ?? null;
356359
}
357360

358-
return $request->getPost($this->tokenName) ?? $tokenName;
361+
return null;
359362
}
360363

361364
/**

0 commit comments

Comments
 (0)