Skip to content

Commit aefdde5

Browse files
committed
Adds private claims to the grant types
1 parent 517403b commit aefdde5

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

src/AuthorizationServer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use League\OAuth2\Server\Exception\OAuthServerException;
1717
use League\OAuth2\Server\Grant\GrantTypeInterface;
1818
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
19+
use League\OAuth2\Server\Repositories\ClaimRepositoryInterface;
1920
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
2021
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
2122
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
@@ -69,6 +70,11 @@ class AuthorizationServer implements EmitterAwareInterface
6970
*/
7071
private $scopeRepository;
7172

73+
/**
74+
* @var ClaimRepositoryInterface
75+
*/
76+
private $claimRepository;
77+
7278
/**
7379
* @var string|Key
7480
*/
@@ -93,13 +99,15 @@ public function __construct(
9399
ClientRepositoryInterface $clientRepository,
94100
AccessTokenRepositoryInterface $accessTokenRepository,
95101
ScopeRepositoryInterface $scopeRepository,
102+
ClaimRepositoryInterface $claimRepository,
96103
$privateKey,
97104
$encryptionKey,
98105
ResponseTypeInterface $responseType = null
99106
) {
100107
$this->clientRepository = $clientRepository;
101108
$this->accessTokenRepository = $accessTokenRepository;
102109
$this->scopeRepository = $scopeRepository;
110+
$this->claimRepository = $claimRepository;
103111

104112
if ($privateKey instanceof CryptKey === false) {
105113
$privateKey = new CryptKey($privateKey);
@@ -132,6 +140,7 @@ public function enableGrantType(GrantTypeInterface $grantType, DateInterval $acc
132140
$grantType->setAccessTokenRepository($this->accessTokenRepository);
133141
$grantType->setClientRepository($this->clientRepository);
134142
$grantType->setScopeRepository($this->scopeRepository);
143+
$grantType->setClaimRepository($this->claimRepository);
135144
$grantType->setDefaultScope($this->defaultScope);
136145
$grantType->setPrivateKey($this->privateKey);
137146
$grantType->setEmitter($this->getEmitter());

src/Grant/AuthCodeGrant.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ public function respondToAccessTokenRequest(
161161
}
162162
$privateClaims = [];
163163
if($this->claimRepository){
164-
$privateClaims = $this->claimRepository->getClaims();
164+
$privateClaims = $this->claimRepository->getClaims(
165+
$privateClaims,
166+
$this->getIdentifier(),
167+
$client,
168+
$authCodePayload->user_id
169+
);
165170
}
166171

167172
// Issue and persist new access token

src/Grant/ClientCredentialsGrant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function respondToAccessTokenRequest(
5050

5151
$privateClaims = [];
5252
if($this->claimRepository){
53-
$privateClaims = $this->claimRepository->getClaims();
53+
$privateClaims = $this->claimRepository->getClaims($privateClaims, $this->getIdentifier(), $client);
5454
}
5555

5656
// Issue and persist access token

src/Grant/ImplicitGrant.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ public function completeAuthorizationRequest(AuthorizationRequest $authorization
188188

189189
$privateClaims = [];
190190
if($this->claimRepository){
191-
$privateClaims = $this->claimRepository->getClaims();
191+
$privateClaims = $this->claimRepository->getClaims(
192+
$privateClaims,
193+
$this->getIdentifier(),
194+
$authorizationRequest->getClient(),
195+
$authorizationRequest->getUser()->getIdentifier()
196+
);
192197
}
193198

194199
$accessToken = $this->issueAccessToken(

src/Grant/PasswordGrant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function respondToAccessTokenRequest(
5858

5959
$privateClaims = [];
6060
if($this->claimRepository){
61-
$privateClaims = $this->claimRepository->getClaims();
61+
$privateClaims = $this->claimRepository->getClaims($privateClaims, $this->getIdentifier(), $client, $user->getIdentifier());
6262
}
6363

6464
// Issue and persist new access token

src/Grant/RefreshTokenGrant.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ public function respondToAccessTokenRequest(
6363
$this->accessTokenRepository->revokeAccessToken($oldRefreshToken['access_token_id']);
6464
$this->refreshTokenRepository->revokeRefreshToken($oldRefreshToken['refresh_token_id']);
6565

66-
$privateClaim = [];
66+
$privateClaims = [];
6767
if($this->claimRepository){
68-
$privateClaim = $this->claimRepository->getClaims();
68+
$privateClaims = $this->claimRepository->getClaims(
69+
$privateClaims,
70+
$this->getIdentifier(),
71+
$client,
72+
$oldRefreshToken['user_id']
73+
);
6974
}
7075

7176
// Issue and persist new access token
@@ -74,7 +79,7 @@ public function respondToAccessTokenRequest(
7479
$client,
7580
$oldRefreshToken['user_id'],
7681
$scopes,
77-
$privateClaim
82+
$privateClaims
7883
);
7984
$this->getEmitter()->emit(new RequestEvent(RequestEvent::ACCESS_TOKEN_ISSUED, $request));
8085
$responseType->setAccessToken($accessToken);

src/Repositories/ClaimRepositoryInterface.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace League\OAuth2\Server\Repositories;
1111

1212
use League\OAuth2\Server\Entities\ClaimEntityInterface;
13+
use League\OAuth2\Server\Entities\ClientEntityInterface;
1314

1415
/**
1516
* Claim repository interface.
@@ -22,5 +23,9 @@ interface ClaimRepositoryInterface extends RepositoryInterface
2223
*
2324
* @return ClaimEntityInterface[]
2425
*/
25-
public function getClaims();
26+
public function getClaims(
27+
array $claims,
28+
$grantType,
29+
ClientEntityInterface $clientEntity,
30+
$userIdentifier = null);
2631
}

0 commit comments

Comments
 (0)