mirror of
https://github.com/elyby/accounts.git
synced 2024-11-26 16:52:02 +05:30
Fixes #16. Correctly wrap Yii2's request into the PSR's ServerRequest object
This commit is contained in:
parent
262bdbc08e
commit
99c983c3ea
@ -78,6 +78,8 @@ return [
|
||||
'baseUrl' => '/api',
|
||||
'enableCsrfCookie' => false,
|
||||
'parsers' => [
|
||||
'application/json' => yii\web\JsonParser::class,
|
||||
'multipart/form-data' => yii\web\MultipartFormDataParser::class,
|
||||
'*' => api\request\RequestParser::class,
|
||||
],
|
||||
],
|
||||
|
@ -63,7 +63,15 @@ class AuthorizationController extends Controller {
|
||||
}
|
||||
|
||||
private function getServerRequest(): ServerRequestInterface {
|
||||
return ServerRequest::fromGlobals();
|
||||
$request = Yii::$app->request;
|
||||
|
||||
return (new ServerRequest(
|
||||
$request->getMethod(),
|
||||
$request->getAbsoluteUrl() . '?' . $request->getQueryString(),
|
||||
$request->getHeaders()->toArray(),
|
||||
))
|
||||
->withParsedBody($request->getBodyParams())
|
||||
->withQueryParams($request->getQueryParams());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ namespace api\tests\functional\oauth;
|
||||
|
||||
use api\tests\functional\_steps\OauthSteps;
|
||||
|
||||
class AccessTokenCest {
|
||||
final class AccessTokenCest {
|
||||
|
||||
public function successfullyIssueToken(OauthSteps $I) {
|
||||
public function successfullyIssueTokenWithUrlEncodedBody(OauthSteps $I): void {
|
||||
$I->wantTo('complete oauth flow and obtain access_token');
|
||||
$authCode = $I->obtainAuthCode();
|
||||
$I->sendPOST('/api/oauth2/v1/token', [
|
||||
@ -26,16 +26,17 @@ class AccessTokenCest {
|
||||
$I->cantSeeResponseJsonMatchesJsonPath('$.refresh_token');
|
||||
}
|
||||
|
||||
public function successfullyIssueOfflineToken(OauthSteps $I) {
|
||||
public function successfullyIssueOfflineTokenWithJsonEncodedBody(OauthSteps $I): void {
|
||||
$I->wantTo('complete oauth flow with offline_access scope and obtain access_token and refresh_token');
|
||||
$authCode = $I->obtainAuthCode(['offline_access']);
|
||||
$I->sendPOST('/api/oauth2/v1/token', [
|
||||
$I->haveHttpHeader('Content-Type', 'application/json');
|
||||
$I->sendPOST('/api/oauth2/v1/token', json_encode([
|
||||
'grant_type' => 'authorization_code',
|
||||
'code' => $authCode,
|
||||
'client_id' => 'ely',
|
||||
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
||||
'redirect_uri' => 'http://ely.by',
|
||||
]);
|
||||
]));
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseContainsJson([
|
||||
'token_type' => 'Bearer',
|
||||
|
Loading…
Reference in New Issue
Block a user