1 | <?php |
||
42 | abstract class AbstractGrant implements GrantTypeInterface |
||
43 | { |
||
44 | use EmitterAwareTrait, CryptTrait, RequestValidatorTrait; |
||
45 | |||
46 | const SCOPE_DELIMITER_STRING = ' '; |
||
47 | |||
48 | const MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS = 10; |
||
49 | |||
50 | /** |
||
51 | * @var ClientRepositoryInterface |
||
52 | */ |
||
53 | protected $clientRepository; |
||
54 | |||
55 | /** |
||
56 | * @var AccessTokenRepositoryInterface |
||
57 | */ |
||
58 | protected $accessTokenRepository; |
||
59 | |||
60 | /** |
||
61 | * @var ScopeRepositoryInterface |
||
62 | */ |
||
63 | protected $scopeRepository; |
||
64 | |||
65 | /** |
||
66 | * @var AuthCodeRepositoryInterface |
||
67 | */ |
||
68 | protected $authCodeRepository; |
||
69 | |||
70 | /** |
||
71 | * @var RefreshTokenRepositoryInterface |
||
72 | */ |
||
73 | protected $refreshTokenRepository; |
||
74 | |||
75 | /** |
||
76 | * @var UserRepositoryInterface |
||
77 | */ |
||
78 | protected $userRepository; |
||
79 | |||
80 | /** |
||
81 | * @var DateInterval |
||
82 | */ |
||
83 | protected $refreshTokenTTL; |
||
84 | |||
85 | /** |
||
86 | * @var CryptKey |
||
87 | */ |
||
88 | protected $privateKey; |
||
89 | |||
90 | /** |
||
91 | * @string |
||
92 | */ |
||
93 | protected $defaultScope; |
||
94 | |||
95 | /** |
||
96 | * @return ClientRepositoryInterface |
||
97 | */ |
||
98 | 41 | public function getClientRepository() |
|
102 | |||
103 | /** |
||
104 | * @param ClientRepositoryInterface $clientRepository |
||
105 | */ |
||
106 | 64 | public function setClientRepository(ClientRepositoryInterface $clientRepository) |
|
110 | |||
111 | /** |
||
112 | * @param AccessTokenRepositoryInterface $accessTokenRepository |
||
113 | */ |
||
114 | 42 | public function setAccessTokenRepository(AccessTokenRepositoryInterface $accessTokenRepository) |
|
118 | |||
119 | /** |
||
120 | * @param ScopeRepositoryInterface $scopeRepository |
||
121 | */ |
||
122 | 37 | public function setScopeRepository(ScopeRepositoryInterface $scopeRepository) |
|
126 | |||
127 | /** |
||
128 | * @param RefreshTokenRepositoryInterface $refreshTokenRepository |
||
129 | */ |
||
130 | 56 | public function setRefreshTokenRepository(RefreshTokenRepositoryInterface $refreshTokenRepository) |
|
134 | |||
135 | /** |
||
136 | * @param AuthCodeRepositoryInterface $authCodeRepository |
||
137 | */ |
||
138 | 42 | public function setAuthCodeRepository(AuthCodeRepositoryInterface $authCodeRepository) |
|
142 | |||
143 | /** |
||
144 | * @param UserRepositoryInterface $userRepository |
||
145 | */ |
||
146 | 5 | public function setUserRepository(UserRepositoryInterface $userRepository) |
|
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | 1 | public function setRefreshTokenTTL(DateInterval $refreshTokenTTL) |
|
158 | |||
159 | /** |
||
160 | * Set the private key |
||
161 | * |
||
162 | * @param CryptKey $key |
||
163 | */ |
||
164 | 20 | public function setPrivateKey(CryptKey $key) |
|
168 | |||
169 | /** |
||
170 | * @param string $scope |
||
171 | */ |
||
172 | 16 | public function setDefaultScope($scope) |
|
176 | |||
177 | /** |
||
178 | * Validate scopes in the request. |
||
179 | * |
||
180 | * @param string|array $scopes |
||
181 | * @param string $redirectUri |
||
182 | * |
||
183 | * @throws OAuthServerException |
||
184 | * |
||
185 | * @return ScopeEntityInterface[] |
||
186 | */ |
||
187 | 34 | public function validateScopes($scopes, $redirectUri = null) |
|
207 | |||
208 | /** |
||
209 | * Converts a scopes query string to an array to easily iterate for validation. |
||
210 | * |
||
211 | * @param string $scopes |
||
212 | * |
||
213 | * @return array |
||
214 | */ |
||
215 | private function convertScopesQueryStringToArray($scopes) |
||
221 | |||
222 | /** |
||
223 | * Issue an access token. |
||
224 | * |
||
225 | * @param DateInterval $accessTokenTTL |
||
226 | * @param ClientEntityInterface $client |
||
227 | * @param string|null $userIdentifier |
||
228 | * @param ScopeEntityInterface[] $scopes |
||
229 | * |
||
230 | * @throws OAuthServerException |
||
231 | * @throws UniqueTokenIdentifierConstraintViolationException |
||
232 | * |
||
233 | * @return AccessTokenEntityInterface |
||
234 | */ |
||
235 | 17 | protected function issueAccessToken( |
|
265 | |||
266 | /** |
||
267 | * Issue an auth code. |
||
268 | * |
||
269 | * @param DateInterval $authCodeTTL |
||
270 | * @param ClientEntityInterface $client |
||
271 | * @param string $userIdentifier |
||
272 | * @param string|null $redirectUri |
||
273 | * @param ScopeEntityInterface[] $scopes |
||
274 | * |
||
275 | * @throws OAuthServerException |
||
276 | * @throws UniqueTokenIdentifierConstraintViolationException |
||
277 | * |
||
278 | * @return AuthCodeEntityInterface |
||
279 | */ |
||
280 | 6 | protected function issueAuthCode( |
|
315 | |||
316 | /** |
||
317 | * @param AccessTokenEntityInterface $accessToken |
||
318 | * |
||
319 | * @throws OAuthServerException |
||
320 | * @throws UniqueTokenIdentifierConstraintViolationException |
||
321 | * |
||
322 | * @return RefreshTokenEntityInterface |
||
323 | */ |
||
324 | 10 | protected function issueRefreshToken(AccessTokenEntityInterface $accessToken) |
|
345 | |||
346 | /** |
||
347 | * Generate a new unique identifier. |
||
348 | * |
||
349 | * @param int $length |
||
350 | * |
||
351 | * @throws OAuthServerException |
||
352 | * |
||
353 | * @return string |
||
354 | */ |
||
355 | 25 | protected function generateUniqueIdentifier($length = 40) |
|
370 | |||
371 | /** |
||
372 | * {@inheritdoc} |
||
373 | */ |
||
374 | 5 | public function canRespondToAccessTokenRequest(ServerRequestInterface $request) |
|
383 | |||
384 | /** |
||
385 | * {@inheritdoc} |
||
386 | */ |
||
387 | 1 | public function canRespondToAuthorizationRequest(ServerRequestInterface $request) |
|
391 | |||
392 | /** |
||
393 | * {@inheritdoc} |
||
394 | */ |
||
395 | 1 | public function validateAuthorizationRequest(ServerRequestInterface $request) |
|
399 | |||
400 | /** |
||
401 | * {@inheritdoc} |
||
402 | */ |
||
403 | 1 | public function completeAuthorizationRequest(AuthorizationRequest $authorizationRequest) |
|
407 | } |
||
408 |