Skip to content

Commit c700f56

Browse files
committed
Fixes made for 3.x ported to 4.x
1 parent cf08843 commit c700f56

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

src/Authorizer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ public function authCodeRequestDeniedRedirectUri()
133133
{
134134
$error = new AccessDeniedException;
135135
return $this->getRedirectUriGenerator()->make($this->getAuthCodeRequestParam('redirect_uri'), [
136-
'error' => $error->errorType,
137-
'error_description' => $error->getMessage()
138-
]
136+
'error' => $error->errorType,
137+
'error_description' => $error->getMessage()
138+
]
139139
);
140140
}
141141

@@ -177,7 +177,7 @@ public function validateAccessToken($httpHeadersOnly = false, $accessToken = nul
177177
*/
178178
public function getScopes()
179179
{
180-
return $this->checker->getScopes();
180+
return $this->checker->getAccessToken()->getScopes();
181181
}
182182

183183
/**
@@ -187,7 +187,7 @@ public function getScopes()
187187
*/
188188
public function hasScope($scope)
189189
{
190-
return $this->checker->hasScope($scope);
190+
return $this->checker->getAccessToken()->hasScope($scope);
191191
}
192192

193193
/**
@@ -196,7 +196,7 @@ public function hasScope($scope)
196196
*/
197197
public function getResourceOwnerId()
198198
{
199-
return $this->checker->getOwnerId();
199+
return $this->checker->getAccessToken()->getSession()->getOwnerId();
200200
}
201201

202202
/**
@@ -205,7 +205,7 @@ public function getResourceOwnerId()
205205
*/
206206
public function getResourceOwnerType()
207207
{
208-
return $this->checker->getOwnerType();
208+
return $this->checker->getAccessToken()->getSession()->getOwnerType();
209209
}
210210

211211
/**
@@ -214,7 +214,7 @@ public function getResourceOwnerType()
214214
*/
215215
public function getClientId()
216216
{
217-
return $this->checker->getClientId();
217+
return $this->checker->getAccessToken()->getSession()->getClient()->getId();
218218
}
219219

220220
/**

tests/unit/LucaDegasperi/OAuth2Server/AuthorizerSpec.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace unit\LucaDegasperi\OAuth2Server;
44

55
use League\OAuth2\Server\AuthorizationServer;
6+
use League\OAuth2\Server\Entity\AccessTokenEntity;
7+
use League\OAuth2\Server\Entity\ClientEntity;
8+
use League\OAuth2\Server\Entity\SessionEntity;
69
use League\OAuth2\Server\Grant\AuthCodeGrant;
710
use League\OAuth2\Server\ResourceServer;
811
use League\OAuth2\Server\TokenType\TokenTypeInterface;
@@ -47,36 +50,46 @@ function it_issues_an_auth_code(AuthorizationServer $issuer, AuthCodeGrant $auth
4750
$this->issueAuthCode('user', '1', ['foo' => 'bar'])->shouldReturn('baz');
4851
}
4952

50-
function it_returns_the_current_scopes(ResourceServer $checker)
53+
function it_returns_the_current_scopes(ResourceServer $checker, AccessTokenEntity $accessTokenEntity)
5154
{
52-
$checker->getScopes()->willReturn(['foo', 'bar'])->shouldBeCalled();
55+
$accessTokenEntity->getScopes()->willReturn(['foo','bar']);
56+
$checker->getAccessToken()->willReturn($accessTokenEntity)->shouldBeCalled();
5357
$this->getScopes()->shouldReturn(['foo', 'bar']);
5458
}
5559

56-
function it_checks_if_a_scope_is_included_into_the_current_ones(ResourceServer $checker)
60+
function it_checks_if_a_scope_is_included_into_the_current_ones(ResourceServer $checker, AccessTokenEntity $accessTokenEntity)
5761
{
58-
$checker->hasScope('foo')->willReturn(true)->shouldBeCalled();
62+
$accessTokenEntity->hasScope('foo')->willReturn(true)->shouldBeCalled();
63+
$checker->getAccessToken()->willReturn($accessTokenEntity)->shouldBeCalled();
5964
$this->hasScope('foo')->shouldReturn(true);
6065

61-
$checker->hasScope(['foo', 'bar'])->willReturn(false)->shouldBeCalled();
66+
$accessTokenEntity->hasScope(['foo', 'bar'])->willReturn(false)->shouldBecalled();
67+
$checker->getAccessToken()->willReturn($accessTokenEntity)->shouldBeCalled();
6268
$this->hasScope(['foo', 'bar'])->shouldReturn(false);
6369
}
6470

65-
function it_returns_the_resource_owner_id(ResourceServer $checker)
71+
function it_returns_the_resource_owner_id(ResourceServer $checker, AccessTokenEntity $accessTokenEntity, SessionEntity $sessionEntity)
6672
{
67-
$checker->getOwnerId()->willReturn('1')->shouldBeCalled();
73+
$sessionEntity->getOwnerId()->willReturn('1')->shouldBeCalled();
74+
$accessTokenEntity->getSession()->willReturn($sessionEntity)->shouldBeCalled();
75+
$checker->getAccessToken()->willReturn($accessTokenEntity)->shouldBeCalled();
6876
$this->getResourceOwnerId()->shouldReturn('1');
6977
}
7078

71-
function it_returns_the_resource_owner_type(ResourceServer $checker)
79+
function it_returns_the_resource_owner_type(ResourceServer $checker, AccessTokenEntity $accessTokenEntity, SessionEntity $sessionEntity)
7280
{
73-
$checker->getOwnerType()->willReturn('user')->shouldBeCalled();
81+
$sessionEntity->getOwnerType()->willReturn('user')->shouldBeCalled();
82+
$accessTokenEntity->getSession()->willReturn($sessionEntity)->shouldBeCalled();
83+
$checker->getAccessToken()->willReturn($accessTokenEntity)->shouldBeCalled();
7484
$this->getResourceOwnerType()->shouldReturn('user');
7585
}
7686

77-
function it_returns_the_client_id(ResourceServer $checker)
87+
function it_returns_the_client_id(ResourceServer $checker, AccessTokenEntity $accessTokenEntity, SessionEntity $sessionEntity, ClientEntity $clientEntity)
7888
{
79-
$checker->getClientId()->willReturn('1')->shouldBeCalled();
89+
$clientEntity->getId()->willReturn('1')->shouldBeCalled();
90+
$sessionEntity->getClient()->willReturn($clientEntity)->shouldBeCalled();
91+
$accessTokenEntity->getSession()->willReturn($sessionEntity)->shouldBeCalled();
92+
$checker->getAccessToken()->willReturn($accessTokenEntity)->shouldBeCalled();
8093
$this->getClientId()->shouldReturn('1');
8194
}
8295

0 commit comments

Comments
 (0)