Skip to content

Commit ef409bb

Browse files
committed
Merge pull request #182 from pulkitjalan/patch-1
Updated FluentScope get to now support client id
2 parents 90045a4 + 3c727ad commit ef409bb

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

src/Storage/FluentScope.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ public function areScopesLimitedToGrants()
6060
*
6161
* @param string $scope The scope
6262
* @param string $grantType The grant type used in the request (default = "null")
63+
* @param string $clientId The client id used for the request (default = "null")
6364
* @return \League\OAuth2\Server\Entity\ScopeEntity|null If the scope doesn't exist return false
6465
*/
65-
public function get($scope, $grantType = null)
66+
public function get($scope, $grantType = null, $clientId = null)
6667
{
6768
$query = $this->getConnection()->table('oauth_scopes')
6869
->select('oauth_scopes.id as id', 'oauth_scopes.description as description')
6970
->where('oauth_scopes.id', $scope);
7071

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

7777
if ($this->limitScopesToGrants === true and ! is_null($grantType)) {
7878
$query = $query->join('oauth_grant_scopes', 'oauth_scopes.id', '=', 'oauth_grant_scopes.scope_id')

tests/integration/FluentScopeTest.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,33 @@ public function test_get_unexisting_scope()
2020
$repo->limitClientsToScopes(true);
2121
$repo->limitScopesToGrants(true);
2222

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

2525
$this->assertTrue($repo->areClientsLimitedToScopes());
2626
$this->assertTrue($repo->areScopesLimitedToGrants());
2727
$this->assertNull($result);
2828
}
2929

30-
/*public function test_get_scope_with_grant()
30+
public function test_get_scope_with_client_only()
3131
{
3232
$repo = $this->getScopeRepository();
3333
$repo->limitClientsToScopes(true);
34-
$repo->limitScopesToGrants(true);
3534

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

38-
$this->resultAssertions($result);
39-
}*/
37+
$this->assertIsScope($result);
38+
}
4039

41-
/*public function test_get_scope_with_client_only()
40+
public function test_get_scope_with_invalid_client_only()
4241
{
43-
$repo = new FluentScope();
42+
$repo = $this->getScopeRepository();
4443
$repo->limitClientsToScopes(true);
4544

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

48-
$this->assertIsScope($result);
49-
}*/
47+
$this->assertTrue($repo->areClientsLimitedToScopes());
48+
$this->assertNull($result);
49+
}
5050

5151
public function test_get_scope_with_grant_only()
5252
{
@@ -58,6 +58,30 @@ public function test_get_scope_with_grant_only()
5858
$this->assertIsScope($result);
5959
}
6060

61+
public function test_get_scope_with_invalid_grant_only()
62+
{
63+
$repo = $this->getScopeRepository();
64+
$repo->limitScopesToGrants(true);
65+
66+
$result = $repo->get('scope1', 'invalidgrant');
67+
68+
$this->assertTrue($repo->areScopesLimitedToGrants());
69+
$this->assertNull($result);
70+
}
71+
72+
public function test_get_scope_with_client_and_grant()
73+
{
74+
$repo = $this->getScopeRepository();
75+
$repo->limitClientsToScopes(true);
76+
$repo->limitScopesToGrants(true);
77+
78+
$result = $repo->get('scope1', 'grant1', 'client1id');
79+
80+
$this->assertTrue($repo->areClientsLimitedToScopes());
81+
$this->assertTrue($repo->areScopesLimitedToGrants());
82+
$this->assertIsScope($result);
83+
}
84+
6185
public function test_get_scope()
6286
{
6387
$repo = $this->getScopeRepository();

0 commit comments

Comments
 (0)