Last active
October 28, 2019 23:43
-
-
Save angelxmoreno/09713d6b515c371da605bdf4ed501c54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Authentication\Authenticator; | |
use Authentication\Authenticator\FormAuthenticator; | |
use Psr\Http\Message\ServerRequestInterface; | |
/** | |
* Class ApiAuthenticator | |
* @package App\Authentication\Authenticator | |
*/ | |
class JsonAuthenticator extends FormAuthenticator | |
{ | |
protected function _getData(ServerRequestInterface $request) | |
{ | |
$fields = $this->_config['fields']; | |
$body = json_decode($request->getBody()->getContents(), true); | |
$data = []; | |
foreach ($fields as $key => $field) { | |
if (!isset($body[$field])) { | |
return null; | |
} | |
$value = $body[$field]; | |
if (!is_string($value) || !strlen($value)) { | |
return null; | |
} | |
$data[$key] = $value; | |
} | |
return $data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This bit is no longer needed since CakePHP itself has a BodyParserMiddleware that addresses this.
cakephp/authentication#185
cakephp/cakephp#11875