1 | <?php |
||
29 | class AuthorizationServer implements EmitterAwareInterface |
||
30 | { |
||
31 | use EmitterAwareTrait; |
||
32 | |||
33 | /** |
||
34 | * @var GrantTypeInterface[] |
||
35 | */ |
||
36 | protected $enabledGrantTypes = []; |
||
37 | |||
38 | /** |
||
39 | * @var DateInterval[] |
||
40 | */ |
||
41 | protected $grantTypeAccessTokenTTL = []; |
||
42 | |||
43 | /** |
||
44 | * @var CryptKey |
||
45 | */ |
||
46 | protected $privateKey; |
||
47 | |||
48 | /** |
||
49 | * @var CryptKey |
||
50 | */ |
||
51 | protected $publicKey; |
||
52 | |||
53 | /** |
||
54 | * @var ResponseTypeInterface |
||
55 | */ |
||
56 | protected $responseType; |
||
57 | |||
58 | /** |
||
59 | * @var ClientRepositoryInterface |
||
60 | */ |
||
61 | private $clientRepository; |
||
62 | |||
63 | /** |
||
64 | * @var AccessTokenRepositoryInterface |
||
65 | */ |
||
66 | private $accessTokenRepository; |
||
67 | |||
68 | /** |
||
69 | * @var ScopeRepositoryInterface |
||
70 | */ |
||
71 | private $scopeRepository; |
||
72 | |||
73 | /** |
||
74 | * @var string|Key |
||
75 | */ |
||
76 | private $encryptionKey; |
||
77 | |||
78 | /** |
||
79 | * @var string |
||
80 | */ |
||
81 | private $defaultScope = ''; |
||
82 | |||
83 | /** |
||
84 | * New server instance. |
||
85 | * |
||
86 | * @param ClientRepositoryInterface $clientRepository |
||
87 | * @param AccessTokenRepositoryInterface $accessTokenRepository |
||
88 | * @param ScopeRepositoryInterface $scopeRepository |
||
89 | * @param CryptKey|string $privateKey |
||
90 | * @param string|Key $encryptionKey |
||
91 | * @param null|ResponseTypeInterface $responseType |
||
92 | */ |
||
93 | 11 | public function __construct( |
|
94 | ClientRepositoryInterface $clientRepository, |
||
95 | AccessTokenRepositoryInterface $accessTokenRepository, |
||
96 | ScopeRepositoryInterface $scopeRepository, |
||
97 | $privateKey, |
||
98 | $encryptionKey, |
||
99 | ResponseTypeInterface $responseType = null |
||
100 | ) { |
||
101 | 11 | $this->clientRepository = $clientRepository; |
|
102 | 11 | $this->accessTokenRepository = $accessTokenRepository; |
|
103 | 11 | $this->scopeRepository = $scopeRepository; |
|
104 | |||
105 | 11 | if ($privateKey instanceof CryptKey === false) { |
|
106 | 11 | $privateKey = new CryptKey($privateKey); |
|
107 | } |
||
108 | |||
109 | 11 | $this->privateKey = $privateKey; |
|
110 | 11 | $this->encryptionKey = $encryptionKey; |
|
111 | |||
112 | 11 | if ($responseType === null) { |
|
113 | 6 | $responseType = new BearerTokenResponse(); |
|
114 | } else { |
||
115 | 5 | $responseType = clone $responseType; |
|
116 | } |
||
117 | |||
118 | 11 | $this->responseType = $responseType; |
|
119 | 11 | } |
|
120 | |||
121 | /** |
||
122 | * Enable a grant type on the server. |
||
123 | * |
||
124 | * @param GrantTypeInterface $grantType |
||
125 | * @param null|DateInterval $accessTokenTTL |
||
126 | */ |
||
127 | 7 | public function enableGrantType(GrantTypeInterface $grantType, DateInterval $accessTokenTTL = null) |
|
144 | |||
145 | /** |
||
146 | * Validate an authorization request |
||
147 | * |
||
148 | * @param ServerRequestInterface $request |
||
149 | * |
||
150 | * @throws OAuthServerException |
||
151 | * |
||
152 | * @return AuthorizationRequest |
||
153 | */ |
||
154 | 3 | public function validateAuthorizationRequest(ServerRequestInterface $request) |
|
164 | |||
165 | /** |
||
166 | * Complete an authorization request |
||
167 | * |
||
168 | * @param AuthorizationRequest $authRequest |
||
169 | * @param ResponseInterface $response |
||
170 | * |
||
171 | * @return ResponseInterface |
||
172 | */ |
||
173 | 1 | public function completeAuthorizationRequest(AuthorizationRequest $authRequest, ResponseInterface $response) |
|
179 | |||
180 | /** |
||
181 | * Validate a device authorization request |
||
182 | * |
||
183 | * @param ServerRequestInterface $request |
||
184 | * |
||
185 | * @return DeviceAuthorizationRequest |
||
186 | * |
||
187 | * @throws OAuthServerException |
||
188 | */ |
||
189 | public function validateDeviceAuthorizationRequest(ServerRequestInterface $request) |
||
199 | |||
200 | /** |
||
201 | * Complete a device authorization request |
||
202 | * |
||
203 | * @param DeviceAuthorizationRequest $deviceRequest |
||
204 | * @param ResponseInterface $response |
||
205 | * |
||
206 | * @return ResponseInterface |
||
207 | */ |
||
208 | public function completeDeviceAuthorizationRequest(DeviceAuthorizationRequest $deviceRequest, ResponseInterface $response) |
||
214 | |||
215 | /** |
||
216 | * Return an access token response. |
||
217 | * |
||
218 | * @param ServerRequestInterface $request |
||
219 | * @param ResponseInterface $response |
||
220 | * |
||
221 | * @throws OAuthServerException |
||
222 | * |
||
223 | * @return ResponseInterface |
||
224 | */ |
||
225 | 4 | public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseInterface $response) |
|
244 | |||
245 | /** |
||
246 | * Get the token type that grants will return in the HTTP response. |
||
247 | * |
||
248 | * @return ResponseTypeInterface |
||
249 | */ |
||
250 | 6 | protected function getResponseType() |
|
262 | |||
263 | /** |
||
264 | * Set the default scope for the authorization server. |
||
265 | * |
||
266 | * @param string $defaultScope |
||
267 | */ |
||
268 | 3 | public function setDefaultScope($defaultScope) |
|
272 | } |
||
273 |