Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Client credentials middleware should allow any valid client (#1125) #1132

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Http/Middleware/CheckClientCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CheckClientCredentials extends CheckCredentials
*/
protected function validateCredentials($token)
{
if (! $token || $token->client->firstParty()) {
if (! $token) {
throw new AuthenticationException;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/CheckClientCredentialsForAnyScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CheckClientCredentialsForAnyScope extends CheckCredentials
*/
protected function validateCredentials($token)
{
if (! $token || $token->client->firstParty()) {
if (! $token) {
throw new AuthenticationException;
}
}
Expand Down
31 changes: 0 additions & 31 deletions tests/CheckClientCredentialsForAnyScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,4 @@ public function test_exception_is_thrown_if_token_does_not_have_required_scope()
return 'response';
}, 'baz', 'notbar');
}

/**
* @expectedException \Illuminate\Auth\AuthenticationException
*/
public function test_exception_is_thrown_if_token_belongs_to_first_party_client()
{
$resourceServer = m::mock(ResourceServer::class);
$resourceServer->shouldReceive('validateAuthenticatedRequest')->andReturn($psr = m::mock());
$psr->shouldReceive('getAttribute')->with('oauth_user_id')->andReturn(1);
$psr->shouldReceive('getAttribute')->with('oauth_client_id')->andReturn(1);
$psr->shouldReceive('getAttribute')->with('oauth_access_token_id')->andReturn('token');
$psr->shouldReceive('getAttribute')->with('oauth_scopes')->andReturn(['*']);

$client = m::mock(Client::class);
$client->shouldReceive('firstParty')->andReturnTrue();

$token = m::mock(Token::class);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);

$tokenRepository = m::mock(TokenRepository::class);
$tokenRepository->shouldReceive('find')->with('token')->andReturn($token);

$middleware = new CheckClientCredentialsForAnyScope($resourceServer, $tokenRepository);

$request = Request::create('/');
$request->headers->set('Authorization', 'Bearer token');

$response = $middleware->handle($request, function () {
return 'response';
});
}
}
31 changes: 0 additions & 31 deletions tests/CheckClientCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,35 +136,4 @@ public function test_exception_is_thrown_if_token_does_not_have_required_scopes(
return 'response';
}, 'foo', 'bar');
}

/**
* @expectedException \Illuminate\Auth\AuthenticationException
*/
public function test_exception_is_thrown_if_token_belongs_to_first_party_client()
{
$resourceServer = m::mock(ResourceServer::class);
$resourceServer->shouldReceive('validateAuthenticatedRequest')->andReturn($psr = m::mock());
$psr->shouldReceive('getAttribute')->with('oauth_user_id')->andReturn(1);
$psr->shouldReceive('getAttribute')->with('oauth_client_id')->andReturn(1);
$psr->shouldReceive('getAttribute')->with('oauth_access_token_id')->andReturn('token');
$psr->shouldReceive('getAttribute')->with('oauth_scopes')->andReturn(['*']);

$client = m::mock(Client::class);
$client->shouldReceive('firstParty')->andReturnTrue();

$token = m::mock(Token::class);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);

$tokenRepository = m::mock(TokenRepository::class);
$tokenRepository->shouldReceive('find')->with('token')->andReturn($token);

$middleware = new CheckClientCredentials($resourceServer, $tokenRepository);

$request = Request::create('/');
$request->headers->set('Authorization', 'Bearer token');

$response = $middleware->handle($request, function () {
return 'response';
});
}
}