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