Skip to content

Commit

Permalink
Merge pull request lucadegasperi#182 from pulkitjalan/patch-1
Browse files Browse the repository at this point in the history
Updated FluentScope get to now support client id
  • Loading branch information
lucadegasperi committed Oct 1, 2014
2 parents 90045a4 + 3c727ad commit ef409bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/Storage/FluentScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ public function areScopesLimitedToGrants()
*
* @param string $scope The scope
* @param string $grantType The grant type used in the request (default = "null")
* @param string $clientId The client id used for the request (default = "null")
* @return \League\OAuth2\Server\Entity\ScopeEntity|null If the scope doesn't exist return false
*/
public function get($scope, $grantType = null)
public function get($scope, $grantType = null, $clientId = null)
{
$query = $this->getConnection()->table('oauth_scopes')
->select('oauth_scopes.id as id', 'oauth_scopes.description as description')
->where('oauth_scopes.id', $scope);

// TODO: allow for client scopes limiting
/*if ($this->limitClientsToScopes === true and ! is_null($clientId)) {
if ($this->limitClientsToScopes === true and ! is_null($clientId)) {
$query = $query->join('oauth_client_scopes', 'oauth_scopes.id', '=', 'oauth_client_scopes.scope_id')
->where('oauth_client_scopes.client_id', $clientId);
}*/
}

if ($this->limitScopesToGrants === true and ! is_null($grantType)) {
$query = $query->join('oauth_grant_scopes', 'oauth_scopes.id', '=', 'oauth_grant_scopes.scope_id')
Expand Down
46 changes: 35 additions & 11 deletions tests/integration/FluentScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@ public function test_get_unexisting_scope()
$repo->limitClientsToScopes(true);
$repo->limitScopesToGrants(true);

$result = $repo->get('scope3', 'grant3');
$result = $repo->get('scope3', 'grant3', 'client3id');

$this->assertTrue($repo->areClientsLimitedToScopes());
$this->assertTrue($repo->areScopesLimitedToGrants());
$this->assertNull($result);
}

/*public function test_get_scope_with_grant()
public function test_get_scope_with_client_only()
{
$repo = $this->getScopeRepository();
$repo->limitClientsToScopes(true);
$repo->limitScopesToGrants(true);

$result = $repo->get('scope1', 'grant1');
$result = $repo->get('scope1', null, 'client1id');

$this->resultAssertions($result);
}*/
$this->assertIsScope($result);
}

/*public function test_get_scope_with_client_only()
public function test_get_scope_with_invalid_client_only()
{
$repo = new FluentScope();
$repo = $this->getScopeRepository();
$repo->limitClientsToScopes(true);

$result = $repo->get('scope1', 'client1id');
$result = $repo->get('scope1', null, 'invalidclientid');

$this->assertIsScope($result);
}*/
$this->assertTrue($repo->areClientsLimitedToScopes());
$this->assertNull($result);
}

public function test_get_scope_with_grant_only()
{
Expand All @@ -58,6 +58,30 @@ public function test_get_scope_with_grant_only()
$this->assertIsScope($result);
}

public function test_get_scope_with_invalid_grant_only()
{
$repo = $this->getScopeRepository();
$repo->limitScopesToGrants(true);

$result = $repo->get('scope1', 'invalidgrant');

$this->assertTrue($repo->areScopesLimitedToGrants());
$this->assertNull($result);
}

public function test_get_scope_with_client_and_grant()
{
$repo = $this->getScopeRepository();
$repo->limitClientsToScopes(true);
$repo->limitScopesToGrants(true);

$result = $repo->get('scope1', 'grant1', 'client1id');

$this->assertTrue($repo->areClientsLimitedToScopes());
$this->assertTrue($repo->areScopesLimitedToGrants());
$this->assertIsScope($result);
}

public function test_get_scope()
{
$repo = $this->getScopeRepository();
Expand Down

0 comments on commit ef409bb

Please sign in to comment.