1 | <?php |
||
28 | class AuthorizationServer implements EmitterAwareInterface |
||
29 | { |
||
30 | use EmitterAwareTrait; |
||
31 | |||
32 | /** |
||
33 | * @var GrantTypeInterface[] |
||
34 | */ |
||
35 | protected $enabledGrantTypes = []; |
||
36 | |||
37 | /** |
||
38 | * @var RevokeTokenHandler |
||
39 | */ |
||
40 | protected $revokeTokenHandler = null; |
||
41 | |||
42 | /** |
||
43 | * @var DateInterval[] |
||
44 | */ |
||
45 | protected $grantTypeAccessTokenTTL = []; |
||
46 | |||
47 | /** |
||
48 | * @var CryptKey |
||
49 | */ |
||
50 | protected $privateKey; |
||
51 | |||
52 | /** |
||
53 | * @var CryptKey |
||
54 | */ |
||
55 | protected $publicKey; |
||
56 | |||
57 | /** |
||
58 | * @var ResponseTypeInterface |
||
59 | */ |
||
60 | protected $responseType; |
||
61 | |||
62 | /** |
||
63 | * @var ClientRepositoryInterface |
||
64 | */ |
||
65 | private $clientRepository; |
||
66 | |||
67 | /** |
||
68 | * @var AccessTokenRepositoryInterface |
||
69 | */ |
||
70 | private $accessTokenRepository; |
||
71 | |||
72 | /** |
||
73 | * @var ScopeRepositoryInterface |
||
74 | */ |
||
75 | private $scopeRepository; |
||
76 | |||
77 | /** |
||
78 | * @var string|Key |
||
79 | */ |
||
80 | private $encryptionKey; |
||
81 | |||
82 | /** |
||
83 | * @var string |
||
84 | */ |
||
85 | private $defaultScope = ''; |
||
86 | |||
87 | /** |
||
88 | * New server instance. |
||
89 | * |
||
90 | * @param ClientRepositoryInterface $clientRepository |
||
91 | * @param AccessTokenRepositoryInterface $accessTokenRepository |
||
92 | * @param ScopeRepositoryInterface $scopeRepository |
||
93 | * @param CryptKey|string $privateKey |
||
94 | * @param string|Key $encryptionKey |
||
95 | * @param null|ResponseTypeInterface $responseType |
||
96 | */ |
||
97 | 13 | public function __construct( |
|
98 | ClientRepositoryInterface $clientRepository, |
||
99 | AccessTokenRepositoryInterface $accessTokenRepository, |
||
100 | ScopeRepositoryInterface $scopeRepository, |
||
101 | $privateKey, |
||
102 | $encryptionKey, |
||
103 | ResponseTypeInterface $responseType = null |
||
104 | ) { |
||
105 | 13 | $this->clientRepository = $clientRepository; |
|
106 | 13 | $this->accessTokenRepository = $accessTokenRepository; |
|
107 | 13 | $this->scopeRepository = $scopeRepository; |
|
108 | |||
109 | 13 | if ($privateKey instanceof CryptKey === false) { |
|
110 | 13 | $privateKey = new CryptKey($privateKey); |
|
111 | } |
||
112 | |||
113 | 13 | $this->privateKey = $privateKey; |
|
114 | 13 | $this->encryptionKey = $encryptionKey; |
|
115 | |||
116 | 13 | if ($responseType === null) { |
|
117 | 6 | $responseType = new BearerTokenResponse(); |
|
118 | } else { |
||
119 | 7 | $responseType = clone $responseType; |
|
120 | } |
||
121 | |||
122 | 13 | $this->responseType = $responseType; |
|
123 | 13 | } |
|
124 | |||
125 | /** |
||
126 | * Enable a grant type on the server. |
||
127 | * |
||
128 | * @param GrantTypeInterface $grantType |
||
129 | * @param null|DateInterval $accessTokenTTL |
||
130 | */ |
||
131 | 7 | public function enableGrantType(GrantTypeInterface $grantType, DateInterval $accessTokenTTL = null) |
|
148 | |||
149 | /** |
||
150 | * Validate an authorization request |
||
151 | * |
||
152 | * @param ServerRequestInterface $request |
||
153 | * |
||
154 | * @throws OAuthServerException |
||
155 | * |
||
156 | * @return AuthorizationRequest |
||
157 | */ |
||
158 | 3 | public function validateAuthorizationRequest(ServerRequestInterface $request) |
|
168 | |||
169 | /** |
||
170 | * Complete an authorization request |
||
171 | * |
||
172 | * @param AuthorizationRequest $authRequest |
||
173 | * @param ResponseInterface $response |
||
174 | * |
||
175 | * @return ResponseInterface |
||
176 | */ |
||
177 | 1 | public function completeAuthorizationRequest(AuthorizationRequest $authRequest, ResponseInterface $response) |
|
183 | |||
184 | /** |
||
185 | * Return an access token response. |
||
186 | * |
||
187 | * @param ServerRequestInterface $request |
||
188 | * @param ResponseInterface $response |
||
189 | * |
||
190 | * @throws OAuthServerException |
||
191 | * |
||
192 | * @return ResponseInterface |
||
193 | */ |
||
194 | 4 | public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseInterface $response) |
|
213 | |||
214 | /** |
||
215 | * Enable the revoke token handler on the server. |
||
216 | * |
||
217 | * @param RevokeTokenHandler $handler |
||
218 | */ |
||
219 | 1 | public function enableRevokeTokenHandler(RevokeTokenHandler $handler) |
|
228 | |||
229 | /** |
||
230 | * Return an revoke token response. |
||
231 | * |
||
232 | * @param ServerRequestInterface $request |
||
233 | * @param ResponseInterface $response |
||
234 | * |
||
235 | * @throws OAuthServerException |
||
236 | * |
||
237 | * @return ResponseInterface |
||
238 | */ |
||
239 | 2 | public function respondToRevokeTokenRequest(ServerRequestInterface $request, ResponseInterface $response) |
|
252 | |||
253 | /** |
||
254 | * Get the token type that grants will return in the HTTP response. |
||
255 | * |
||
256 | * @return ResponseTypeInterface |
||
257 | */ |
||
258 | 7 | protected function getResponseType() |
|
270 | |||
271 | /** |
||
272 | * Set the default scope for the authorization server. |
||
273 | * |
||
274 | * @param string $defaultScope |
||
275 | */ |
||
276 | 4 | public function setDefaultScope($defaultScope) |
|
280 | } |
||
281 |