From 97fc8b35c25d4f115a6da0d3740d3f6afe1baf18 Mon Sep 17 00:00:00 2001 From: Sergey Mikhaylov Date: Tue, 5 Apr 2016 23:05:30 +0300 Subject: [PATCH] Implemented getClientScope() --- src/OAuth2Yii/Interfaces/Client.php | 6 ++++++ src/OAuth2Yii/Storage/Client.php | 11 ++++++++--- src/OAuth2Yii/Storage/CustomClient.php | 15 ++++++++++++--- src/OAuth2Yii/Storage/CustomUser.php | 2 ++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/OAuth2Yii/Interfaces/Client.php b/src/OAuth2Yii/Interfaces/Client.php index 5e7fcc4..96ac584 100644 --- a/src/OAuth2Yii/Interfaces/Client.php +++ b/src/OAuth2Yii/Interfaces/Client.php @@ -37,4 +37,10 @@ public function grantTypes($client); * @return bool whether the secret is valid for this client */ public function verifySecret($client, $client_secret); + + /** + * @param array|object $client the client data retrieved from queryClient() + * @return string|null + */ + public function scopes($client); } diff --git a/src/OAuth2Yii/Storage/Client.php b/src/OAuth2Yii/Storage/Client.php index af47167..dff18f2 100644 --- a/src/OAuth2Yii/Storage/Client.php +++ b/src/OAuth2Yii/Storage/Client.php @@ -1,8 +1,8 @@ 'string NOT NULL PRIMARY KEY', 'client_secret' => 'string NOT NULL', 'redirect_uri' => 'text NOT NULL', + 'scope' => 'string', )); } @@ -87,6 +88,10 @@ public function isPublicClient($client_id) public function getClientScope($client_id) { - throw new \CException(501); + $sql = sprintf( + 'SELECT scope FROM %s WHERE client_id = :id', + $this->getTableName() + ); + return $this->getDb()->createCommand($sql)->queryScalar(array(':id' => $client_id)); } } diff --git a/src/OAuth2Yii/Storage/CustomClient.php b/src/OAuth2Yii/Storage/CustomClient.php index 0166f14..202973a 100644 --- a/src/OAuth2Yii/Storage/CustomClient.php +++ b/src/OAuth2Yii/Storage/CustomClient.php @@ -1,13 +1,15 @@ + * + * @method \OAuth2Yii\Interfaces\Client getStorage() */ class CustomClient extends CustomStorage implements ClientInterface, ClientCredentialsInterface { @@ -89,6 +91,13 @@ public function isPublicClient($client_id) public function getClientScope($client_id) { - throw new \CException(501); + $storage = $this->getStorage(); + $client = $storage->queryClient($client_id); + + if (isset($client)) { + return $storage->scopes($client); + } + + return null; } } diff --git a/src/OAuth2Yii/Storage/CustomUser.php b/src/OAuth2Yii/Storage/CustomUser.php index d8c4f7c..8560bc3 100644 --- a/src/OAuth2Yii/Storage/CustomUser.php +++ b/src/OAuth2Yii/Storage/CustomUser.php @@ -7,6 +7,8 @@ * Server storage for user data * * @author Michael Härtl + * + * @method \OAuth2Yii\Interfaces\User getStorage() */ class CustomUser extends CustomStorage implements UserCredentialsInterface {