From 4f259a9dc75387e07e1938fe22e5c73b5df02e5e Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 29 Nov 2016 23:15:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B2=D1=81=D0=B5=20=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=B2=D1=8B=D0=B5=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=20=D0=BD=D0=B0=20=D0=BD=D0=B0=D1=88=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OAuth2/Entities/AuthCodeEntity.php | 4 ++-- .../OAuth2/Entities/SessionEntity.php | 8 ++----- .../OAuth2/Grants/AuthCodeGrant.php | 20 +++++++++++++++++ .../OAuth2/Grants/RefreshTokenGrant.php | 22 +++++++++++++++++++ api/config/config.php | 8 +++++-- api/controllers/OauthController.php | 5 ++--- composer.json | 2 +- 7 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 api/components/OAuth2/Grants/AuthCodeGrant.php create mode 100644 api/components/OAuth2/Grants/RefreshTokenGrant.php diff --git a/api/components/OAuth2/Entities/AuthCodeEntity.php b/api/components/OAuth2/Entities/AuthCodeEntity.php index c216fca..892189e 100644 --- a/api/components/OAuth2/Entities/AuthCodeEntity.php +++ b/api/components/OAuth2/Entities/AuthCodeEntity.php @@ -1,7 +1,7 @@ sessionId = $session->getId(); diff --git a/api/components/OAuth2/Entities/SessionEntity.php b/api/components/OAuth2/Entities/SessionEntity.php index 0d13361..eea6fb3 100644 --- a/api/components/OAuth2/Entities/SessionEntity.php +++ b/api/components/OAuth2/Entities/SessionEntity.php @@ -1,7 +1,7 @@ clientId; } - /** - * @inheritdoc - * @return static - */ - public function associateClient(ClientEntity $client) { + public function associateClient(OriginalClientEntity $client) { parent::associateClient($client); $this->clientId = $client->getId(); diff --git a/api/components/OAuth2/Grants/AuthCodeGrant.php b/api/components/OAuth2/Grants/AuthCodeGrant.php new file mode 100644 index 0000000..cfadbe0 --- /dev/null +++ b/api/components/OAuth2/Grants/AuthCodeGrant.php @@ -0,0 +1,20 @@ +server); + } + + protected function createRefreshTokenEntity() { + return new Entities\RefreshTokenEntity($this->server); + } + + protected function createSessionEntity() { + return new Entities\SessionEntity($this->server); + } + +} diff --git a/api/components/OAuth2/Grants/RefreshTokenGrant.php b/api/components/OAuth2/Grants/RefreshTokenGrant.php new file mode 100644 index 0000000..e1fd3ce --- /dev/null +++ b/api/components/OAuth2/Grants/RefreshTokenGrant.php @@ -0,0 +1,22 @@ +server); + } + + protected function createRefreshTokenEntity() { + return new Entities\RefreshTokenEntity($this->server); + } + + protected function createSessionEntity() { + return new Entities\SessionEntity($this->server); + } + +} diff --git a/api/config/config.php b/api/config/config.php index 37bdd71..4e7ab1a 100644 --- a/api/config/config.php +++ b/api/config/config.php @@ -1,7 +1,7 @@ [ 'class' => api\components\OAuth2\Component::class, 'grantTypes' => ['authorization_code'], + 'grantMap' => [ + 'authorization_code' => api\components\OAuth2\Grants\AuthCodeGrant::class, + 'refresh_token' => api\components\OAuth2\Grants\RefreshTokenGrant::class, + ], ], 'errorHandler' => [ 'class' => api\components\ErrorHandler::class, diff --git a/api/controllers/OauthController.php b/api/controllers/OauthController.php index 916a95f..5c19972 100644 --- a/api/controllers/OauthController.php +++ b/api/controllers/OauthController.php @@ -8,7 +8,6 @@ use common\models\Account; use common\models\OauthClient; use common\models\OauthScope; use League\OAuth2\Server\Exception\OAuthException; -use League\OAuth2\Server\Grant\RefreshTokenGrant; use Yii; use yii\filters\AccessControl; use yii\helpers\ArrayHelper; @@ -195,8 +194,8 @@ class OauthController extends Controller { return; } - $grant = new RefreshTokenGrant(); - $grant->setRefreshTokenRotation(false); + $grantClass = Yii::$app->oauth->grantMap['refresh_token']; + $grant = new $grantClass; $this->getServer()->addGrantType($grant); } diff --git a/composer.json b/composer.json index e168e1b..ae78d32 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "yiisoft/yii2": "2.0.9", "yiisoft/yii2-swiftmailer": "*", "ramsey/uuid": "^3.5.0", - "league/oauth2-server": "dev-improvements#546dbfe85ae7c049cf9266281d228afe8bdd3ef6", + "league/oauth2-server": "dev-improvements#b9277ccd664dcb80a766b73674d21de686cb9dda", "yiisoft/yii2-redis": "~2.0.0", "guzzlehttp/guzzle": "^6.0.0", "php-amqplib/php-amqplib": "^2.6.2",