1 | <?php |
||
25 | class AuthorizationServer implements EmitterAwareInterface |
||
26 | { |
||
27 | use EmitterAwareTrait; |
||
28 | |||
29 | /** |
||
30 | * @var GrantTypeInterface[] |
||
31 | */ |
||
32 | protected $enabledGrantTypes = []; |
||
33 | |||
34 | /** |
||
35 | * @var \DateInterval[] |
||
36 | */ |
||
37 | protected $grantTypeAccessTokenTTL = []; |
||
38 | |||
39 | /** |
||
40 | * @var CryptKey |
||
41 | */ |
||
42 | protected $privateKey; |
||
43 | |||
44 | /** |
||
45 | * @var CryptKey |
||
46 | */ |
||
47 | protected $publicKey; |
||
48 | |||
49 | /** |
||
50 | * @var null|ResponseTypeInterface |
||
51 | */ |
||
52 | protected $responseType; |
||
53 | |||
54 | /** |
||
55 | * @var ClientRepositoryInterface |
||
56 | */ |
||
57 | private $clientRepository; |
||
58 | |||
59 | /** |
||
60 | * @var AccessTokenRepositoryInterface |
||
61 | */ |
||
62 | private $accessTokenRepository; |
||
63 | |||
64 | /** |
||
65 | * @var ScopeRepositoryInterface |
||
66 | */ |
||
67 | private $scopeRepository; |
||
68 | |||
69 | /** |
||
70 | * New server instance. |
||
71 | * |
||
72 | * @param ClientRepositoryInterface $clientRepository |
||
73 | * @param AccessTokenRepositoryInterface $accessTokenRepository |
||
74 | * @param ScopeRepositoryInterface $scopeRepository |
||
75 | * @param CryptKey|string $privateKey |
||
76 | * @param CryptKey|string $publicKey |
||
77 | * @param null|ResponseTypeInterface $responseType |
||
78 | */ |
||
79 | public function __construct( |
||
80 | ClientRepositoryInterface $clientRepository, |
||
81 | AccessTokenRepositoryInterface $accessTokenRepository, |
||
82 | ScopeRepositoryInterface $scopeRepository, |
||
83 | $privateKey, |
||
84 | $publicKey, |
||
85 | ResponseTypeInterface $responseType = null |
||
86 | ) { |
||
87 | $this->clientRepository = $clientRepository; |
||
88 | $this->accessTokenRepository = $accessTokenRepository; |
||
89 | $this->scopeRepository = $scopeRepository; |
||
90 | |||
91 | if ($privateKey instanceof CryptKey === false) { |
||
92 | $privateKey = new CryptKey($privateKey); |
||
|
|||
93 | } |
||
94 | $this->privateKey = $privateKey; |
||
95 | |||
96 | if ($publicKey instanceof CryptKey === false) { |
||
97 | $publicKey = new CryptKey($publicKey); |
||
98 | } |
||
99 | $this->publicKey = $publicKey; |
||
100 | |||
101 | $this->responseType = $responseType; |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Enable a grant type on the server. |
||
106 | * |
||
107 | * @param GrantTypeInterface $grantType |
||
108 | * @param null|\DateInterval $accessTokenTTL |
||
109 | */ |
||
110 | public function enableGrantType(GrantTypeInterface $grantType, \DateInterval $accessTokenTTL = null) |
||
126 | |||
127 | /** |
||
128 | * Validate an authorization request |
||
129 | * |
||
130 | * @param ServerRequestInterface $request |
||
131 | * |
||
132 | * @throws OAuthServerException |
||
133 | * |
||
134 | * @return AuthorizationRequest |
||
135 | */ |
||
136 | public function validateAuthorizationRequest(ServerRequestInterface $request) |
||
146 | |||
147 | /** |
||
148 | * Complete an authorization request |
||
149 | * |
||
150 | * @param AuthorizationRequest $authRequest |
||
151 | * @param ResponseInterface $response |
||
152 | * |
||
153 | * @return ResponseInterface |
||
154 | */ |
||
155 | public function completeAuthorizationRequest(AuthorizationRequest $authRequest, ResponseInterface $response) |
||
161 | |||
162 | /** |
||
163 | * Return an access token response. |
||
164 | * |
||
165 | * @param ServerRequestInterface $request |
||
166 | * @param ResponseInterface $response |
||
167 | * |
||
168 | * @throws OAuthServerException |
||
169 | * |
||
170 | * @return ResponseInterface |
||
171 | */ |
||
172 | public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseInterface $response) |
||
190 | |||
191 | /** |
||
192 | * Get the token type that grants will return in the HTTP response. |
||
193 | * |
||
194 | * @return ResponseTypeInterface |
||
195 | */ |
||
196 | protected function getResponseType() |
||
206 | } |
||
207 |