Skip to content

Commit

Permalink
Merge pull request #5 from Wazelin/feature/client-scope
Browse files Browse the repository at this point in the history
Implemented getClientScope()
  • Loading branch information
wazelin committed Apr 5, 2016
2 parents 07c07e5 + 97fc8b3 commit 16f0750
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/OAuth2Yii/Interfaces/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
11 changes: 8 additions & 3 deletions src/OAuth2Yii/Storage/Client.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace OAuth2Yii\Storage;

use \OAuth2\Storage\ClientInterface;
use \OAuth2\Storage\ClientCredentialsInterface;
use OAuth2\Storage\ClientCredentialsInterface;
use OAuth2\Storage\ClientInterface;

/**
* Server storage for client data
Expand All @@ -28,6 +28,7 @@ protected function createTable()
'client_id' => 'string NOT NULL PRIMARY KEY',
'client_secret' => 'string NOT NULL',
'redirect_uri' => 'text NOT NULL',
'scope' => 'string',
));
}

Expand Down Expand Up @@ -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));
}
}
15 changes: 12 additions & 3 deletions src/OAuth2Yii/Storage/CustomClient.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php
namespace OAuth2Yii\Storage;

use \OAuth2\Storage\ClientInterface;
use \OAuth2\Storage\ClientCredentialsInterface;
use OAuth2\Storage\ClientCredentialsInterface;
use OAuth2\Storage\ClientInterface;

/**
* Server storage for client data
*
* @author Michael Härtl <[email protected]>
*
* @method \OAuth2Yii\Interfaces\Client getStorage()
*/
class CustomClient extends CustomStorage implements ClientInterface, ClientCredentialsInterface
{
Expand Down Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/OAuth2Yii/Storage/CustomUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Server storage for user data
*
* @author Michael Härtl <[email protected]>
*
* @method \OAuth2Yii\Interfaces\User getStorage()
*/
class CustomUser extends CustomStorage implements UserCredentialsInterface
{
Expand Down

0 comments on commit 16f0750

Please sign in to comment.