Skip to content

Commit b282892

Browse files
authored
Merge pull request #1132 from JuanDMeGon/master
[9.x] Client credentials middleware should allow any valid client (#1125)
2 parents e43ef2b + 1314045 commit b282892

4 files changed

+2
-64
lines changed

src/Http/Middleware/CheckClientCredentials.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CheckClientCredentials extends CheckCredentials
1616
*/
1717
protected function validateCredentials($token)
1818
{
19-
if (! $token || $token->client->firstParty()) {
19+
if (! $token) {
2020
throw new AuthenticationException;
2121
}
2222
}

src/Http/Middleware/CheckClientCredentialsForAnyScope.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CheckClientCredentialsForAnyScope extends CheckCredentials
1616
*/
1717
protected function validateCredentials($token)
1818
{
19-
if (! $token || $token->client->firstParty()) {
19+
if (! $token) {
2020
throw new AuthenticationException;
2121
}
2222
}

tests/CheckClientCredentialsForAnyScopeTest.php

-31
Original file line numberDiff line numberDiff line change
@@ -137,35 +137,4 @@ public function test_exception_is_thrown_if_token_does_not_have_required_scope()
137137
return 'response';
138138
}, 'baz', 'notbar');
139139
}
140-
141-
/**
142-
* @expectedException \Illuminate\Auth\AuthenticationException
143-
*/
144-
public function test_exception_is_thrown_if_token_belongs_to_first_party_client()
145-
{
146-
$resourceServer = m::mock(ResourceServer::class);
147-
$resourceServer->shouldReceive('validateAuthenticatedRequest')->andReturn($psr = m::mock());
148-
$psr->shouldReceive('getAttribute')->with('oauth_user_id')->andReturn(1);
149-
$psr->shouldReceive('getAttribute')->with('oauth_client_id')->andReturn(1);
150-
$psr->shouldReceive('getAttribute')->with('oauth_access_token_id')->andReturn('token');
151-
$psr->shouldReceive('getAttribute')->with('oauth_scopes')->andReturn(['*']);
152-
153-
$client = m::mock(Client::class);
154-
$client->shouldReceive('firstParty')->andReturnTrue();
155-
156-
$token = m::mock(Token::class);
157-
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
158-
159-
$tokenRepository = m::mock(TokenRepository::class);
160-
$tokenRepository->shouldReceive('find')->with('token')->andReturn($token);
161-
162-
$middleware = new CheckClientCredentialsForAnyScope($resourceServer, $tokenRepository);
163-
164-
$request = Request::create('/');
165-
$request->headers->set('Authorization', 'Bearer token');
166-
167-
$response = $middleware->handle($request, function () {
168-
return 'response';
169-
});
170-
}
171140
}

tests/CheckClientCredentialsTest.php

-31
Original file line numberDiff line numberDiff line change
@@ -136,35 +136,4 @@ public function test_exception_is_thrown_if_token_does_not_have_required_scopes(
136136
return 'response';
137137
}, 'foo', 'bar');
138138
}
139-
140-
/**
141-
* @expectedException \Illuminate\Auth\AuthenticationException
142-
*/
143-
public function test_exception_is_thrown_if_token_belongs_to_first_party_client()
144-
{
145-
$resourceServer = m::mock(ResourceServer::class);
146-
$resourceServer->shouldReceive('validateAuthenticatedRequest')->andReturn($psr = m::mock());
147-
$psr->shouldReceive('getAttribute')->with('oauth_user_id')->andReturn(1);
148-
$psr->shouldReceive('getAttribute')->with('oauth_client_id')->andReturn(1);
149-
$psr->shouldReceive('getAttribute')->with('oauth_access_token_id')->andReturn('token');
150-
$psr->shouldReceive('getAttribute')->with('oauth_scopes')->andReturn(['*']);
151-
152-
$client = m::mock(Client::class);
153-
$client->shouldReceive('firstParty')->andReturnTrue();
154-
155-
$token = m::mock(Token::class);
156-
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
157-
158-
$tokenRepository = m::mock(TokenRepository::class);
159-
$tokenRepository->shouldReceive('find')->with('token')->andReturn($token);
160-
161-
$middleware = new CheckClientCredentials($resourceServer, $tokenRepository);
162-
163-
$request = Request::create('/');
164-
$request->headers->set('Authorization', 'Bearer token');
165-
166-
$response = $middleware->handle($request, function () {
167-
return 'response';
168-
});
169-
}
170139
}

0 commit comments

Comments
 (0)