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",