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