diff --git a/api/modules/authserver/models/Form.php b/api/modules/authserver/models/Form.php index c749538..02006d8 100644 --- a/api/modules/authserver/models/Form.php +++ b/api/modules/authserver/models/Form.php @@ -16,10 +16,10 @@ abstract class Form extends Model { public function loadByPost() { $data = Yii::$app->request->post(); - // TODO: проверить, парсит ли Yii2 raw body и что он делает, если там неспаршенный json - /*if (empty($data)) { - $data = $request->getJsonRawBody(true); - }*/ + if (empty($data)) { + // TODO: помнится у Yii2 есть механизм парсинга данных входящего запроса. Лучше будет сделать это там + $data = json_decode(Yii::$app->request->getRawBody(), true); + } return $this->load($data); } diff --git a/tests/codeception/api/functional/authserver/AuthorizationCest.php b/tests/codeception/api/functional/authserver/AuthorizationCest.php index b46f120..cf712ed 100644 --- a/tests/codeception/api/functional/authserver/AuthorizationCest.php +++ b/tests/codeception/api/functional/authserver/AuthorizationCest.php @@ -38,6 +38,17 @@ class AuthorizationCest { $this->testSuccessResponse($I); } + public function byEmailWithParamsAsJsonInPostBody(FunctionalTester $I) { + $I->wantTo('authenticate by email and password, passing values as serialized string in post body'); + $this->route->authenticate(json_encode([ + 'username' => 'admin@ely.by', + 'password' => 'password_0', + 'clientToken' => Uuid::uuid4()->toString(), + ])); + + $this->testSuccessResponse($I); + } + public function wrongArguments(FunctionalTester $I) { $I->wantTo('get error on wrong amount of arguments'); $this->route->authenticate([