Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari committed Aug 7, 2024
1 parent b8536ad commit 5d88d42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
15 changes: 7 additions & 8 deletions src/Http/Controllers/AuthorizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,13 @@ protected function parseScopes($authRequest)
*/
protected function hasGrantedScopes($user, $client, $scopes)
{
return collect($scopes)->pluck('id')
->diff($user->tokens()
->where('client_id', $client->getKey())
->where('revoked', false)
->where('expires_at', '>', Date::now())
->pluck('scopes')
->flatten()
)->isEmpty();
return collect($scopes)->pluck('id')->diff(
$user->tokens()->where([
['client_id', '=', $client->getKey()],
['revoked', '=', false],
['expires_at', '>', Date::now()],
])->pluck('scopes')->flatten()
)->isEmpty();
}

/**
Expand Down
8 changes: 3 additions & 5 deletions tests/Unit/AuthorizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function test_authorization_view_is_presented()
$client->shouldReceive('skipsAuthorization')->andReturn(false);
$client->shouldReceive('getKey')->andReturn(1);

$user->shouldReceive('tokens->where->where->where->pluck->flatten')->andReturn(collect());
$user->shouldReceive('tokens->where->pluck->flatten')->andReturn(collect());

$response->shouldReceive('withParameters')->once()->andReturnUsing(function ($data) use ($client, $user, $request) {
$this->assertEquals($client, $data['client']);
Expand Down Expand Up @@ -140,7 +140,7 @@ public function test_request_is_approved_if_valid_token_exists()
$client->shouldReceive('skipsAuthorization')->andReturn(false);
$client->shouldReceive('getKey')->andReturn(1);

$user->shouldReceive('tokens->where->where->where->pluck->flatten')->andReturn(collect(['scope-1']));
$user->shouldReceive('tokens->where->pluck->flatten')->andReturn(collect(['scope-1']));

$this->assertSame('approved', $controller->authorize(
m::mock(ServerRequestInterface::class), $request, $clients
Expand Down Expand Up @@ -186,8 +186,6 @@ public function test_request_is_approved_if_client_can_skip_authorization()

$client->shouldReceive('skipsAuthorization')->andReturn(true);

$user->shouldReceive('tokens->where->where->where->pluck->flatten')->andReturn(collect());

$this->assertSame('approved', $controller->authorize(
m::mock(ServerRequestInterface::class), $request, $clients
)->getContent());
Expand Down Expand Up @@ -279,7 +277,7 @@ public function test_authorization_denied_if_request_has_prompt_equals_to_none()
$client->shouldReceive('skipsAuthorization')->andReturn(false);
$client->shouldReceive('getKey')->andReturn(1);

$user->shouldReceive('tokens->where->where->where->pluck->flatten')->andReturn(collect());
$user->shouldReceive('tokens->where->pluck->flatten')->andReturn(collect());

$controller->authorize(
m::mock(ServerRequestInterface::class), $request, $clients
Expand Down

0 comments on commit 5d88d42

Please sign in to comment.