Skip to content

Commit 8e40ece

Browse files
committed
Set authorizer request in middleware
This closes #496
1 parent a0d7a25 commit 8e40ece

8 files changed

+18
-0
lines changed

src/Middleware/CheckAuthCodeRequestMiddleware.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function __construct(Authorizer $authorizer)
4848
*/
4949
public function handle($request, Closure $next)
5050
{
51+
$this->authorizer->setRequest($request);
52+
5153
$this->authorizer->checkAuthCodeRequest();
5254

5355
return $next($request);

src/Middleware/OAuthClientOwnerMiddleware.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public function __construct(Authorizer $authorizer)
5151
*/
5252
public function handle($request, Closure $next)
5353
{
54+
$this->authorizer->setRequest($request);
55+
5456
if ($this->authorizer->getResourceOwnerType() !== 'client') {
5557
throw new AccessDeniedException();
5658
}

src/Middleware/OAuthMiddleware.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public function handle($request, Closure $next, $scopesString = null)
6767
$scopes = explode('+', $scopesString);
6868
}
6969

70+
$this->authorizer->setRequest($request);
71+
7072
$this->authorizer->validateAccessToken($this->httpHeadersOnly);
7173
$this->validateScopes($scopes);
7274

src/Middleware/OAuthUserOwnerMiddleware.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public function __construct(Authorizer $authorizer)
5151
*/
5252
public function handle($request, Closure $next)
5353
{
54+
$this->authorizer->setRequest($request);
55+
5456
if ($this->authorizer->getResourceOwnerType() !== 'user') {
5557
throw new AccessDeniedException();
5658
}

tests/unit/LucaDegasperi/OAuth2Server/Middleware/CheckAuthCodeRequestMiddlewareSpec.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function it_is_initializable()
4040
public function it_calls_the_next_middleware_on_success(Request $request, Authorizer $authorizer)
4141
{
4242
$authorizer->checkAuthCodeRequest()->shouldBeCalled();
43+
$authorizer->setRequest($request)->shouldBeCalled();
4344

4445
$this->shouldThrow(new MiddlewareException('Called execution of $next'))
4546
->during('handle', [$request, $this->next]);
@@ -48,6 +49,7 @@ public function it_calls_the_next_middleware_on_success(Request $request, Author
4849
public function it_exits_on_error(Request $request, Authorizer $authorizer)
4950
{
5051
$authorizer->checkAuthCodeRequest()->willThrow(new InvalidRequestException('client_id'))->shouldBeCalled();
52+
$authorizer->setRequest($request)->shouldBeCalled();
5153

5254
$this->shouldNotThrow(new MiddlewareException('Called execution of $next'))
5355
->during('handle', [$request, $this->next]);

tests/unit/LucaDegasperi/OAuth2Server/Middleware/OAuthClientOwnerMiddlewareSpec.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function it_is_initializable()
4545
public function it_passes_if_resource_owners_are_allowed(Request $request, Authorizer $authorizer)
4646
{
4747
$authorizer->getResourceOwnerType()->willReturn('client')->shouldBeCalled();
48+
$authorizer->setRequest($request)->shouldBeCalled();
4849

4950
$this->shouldThrow(new MiddlewareException('Called execution of $next'))
5051
->during('handle', [$request, $this->next]);
@@ -53,6 +54,7 @@ public function it_passes_if_resource_owners_are_allowed(Request $request, Autho
5354
public function it_blocks_if_resource_owners_are_not_allowed(Request $request, Authorizer $authorizer)
5455
{
5556
$authorizer->getResourceOwnerType()->willReturn('user')->shouldBeCalled();
57+
$authorizer->setRequest($request)->shouldBeCalled();
5658

5759
$this->shouldThrow(new AccessDeniedException())
5860
->during('handle', [$request, $this->next]);

tests/unit/LucaDegasperi/OAuth2Server/Middleware/OAuthMiddlewareSpec.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function it_is_initializable()
4141
public function it_blocks_invalid_access_tokens(Request $request, Authorizer $authorizer)
4242
{
4343
$authorizer->validateAccessToken(false)->willThrow(new AccessDeniedException())->shouldBeCalled();
44+
$authorizer->setRequest($request)->shouldBeCalled();
4445

4546
$this->shouldNotThrow(new MiddlewareException('Called execution of $next'))
4647
->during('handle', [$request, $this->next]);
@@ -49,6 +50,7 @@ public function it_blocks_invalid_access_tokens(Request $request, Authorizer $au
4950
public function it_passes_with_valid_access_token(Request $request, Authorizer $authorizer)
5051
{
5152
$authorizer->validateAccessToken(false)->shouldBeCalled();
53+
$authorizer->setRequest($request)->shouldBeCalled();
5254

5355
$this->shouldThrow(new MiddlewareException('Called execution of $next'))
5456
->during('handle', [$request, $this->next]);
@@ -57,6 +59,7 @@ public function it_passes_with_valid_access_token(Request $request, Authorizer $
5759
public function it_block_invalid_scopes(Request $request, Authorizer $authorizer)
5860
{
5961
$authorizer->validateAccessToken(false)->shouldBeCalled();
62+
$authorizer->setRequest($request)->shouldBeCalled();
6063
$authorizer->hasScope(['baz'])->willReturn(false)->shouldBeCalled();
6164

6265
$this->shouldThrow(new InvalidScopeException('baz'))
@@ -69,6 +72,7 @@ public function it_block_invalid_scopes(Request $request, Authorizer $authorizer
6972
public function it_passes_with_valid_scopes(Request $request, Authorizer $authorizer)
7073
{
7174
$authorizer->validateAccessToken(false)->shouldBeCalled();
75+
$authorizer->setRequest($request)->shouldBeCalled();
7276
$authorizer->hasScope(['baz'])->willReturn(true)->shouldBeCalled();
7377

7478
$this->shouldNotThrow(new InvalidScopeException('baz'))

tests/unit/LucaDegasperi/OAuth2Server/Middleware/OAuthUserOwnerMiddlewareSpec.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function it_is_initializable()
4545
public function it_passes_if_resource_owners_are_allowed(Request $request, Authorizer $authorizer)
4646
{
4747
$authorizer->getResourceOwnerType()->willReturn('user')->shouldBeCalled();
48+
$authorizer->setRequest($request)->shouldBeCalled();
4849

4950
$this->shouldThrow(new MiddlewareException('Called execution of $next'))
5051
->during('handle', [$request, $this->next]);
@@ -53,6 +54,7 @@ public function it_passes_if_resource_owners_are_allowed(Request $request, Autho
5354
public function it_blocks_if_resource_owners_are_not_allowed(Request $request, Authorizer $authorizer)
5455
{
5556
$authorizer->getResourceOwnerType()->willReturn('client')->shouldBeCalled();
57+
$authorizer->setRequest($request)->shouldBeCalled();
5658

5759
$this->shouldThrow(new AccessDeniedException())
5860
->during('handle', [$request, $this->next]);

0 commit comments

Comments
 (0)