1 | <?php |
||
16 | class Keycloak extends AbstractProvider |
||
17 | { |
||
18 | use BearerAuthorizationTrait; |
||
19 | |||
20 | /** |
||
21 | * Keycloak URL, eg. http://localhost:8080/auth. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | public $authServerUrl = null; |
||
26 | |||
27 | /** |
||
28 | * Realm name, eg. demo. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | public $realm = null; |
||
33 | |||
34 | /** |
||
35 | * Encryption algorithm. |
||
36 | * |
||
37 | * You must specify supported algorithms for your application. See |
||
38 | * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40 |
||
39 | * for a list of spec-compliant algorithms. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | public $encryptionAlgorithm = null; |
||
44 | |||
45 | /** |
||
46 | * Encryption key. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | public $encryptionKey = null; |
||
51 | |||
52 | /** |
||
53 | * Constructs an OAuth 2.0 service provider. |
||
54 | * |
||
55 | * @param array $options An array of options to set on this provider. |
||
56 | * Options include `clientId`, `clientSecret`, `redirectUri`, and `state`. |
||
57 | * Individual providers may introduce more options, as needed. |
||
58 | * @param array $collaborators An array of collaborators that may be used to |
||
59 | * override this provider's default behavior. Collaborators include |
||
60 | * `grantFactory`, `requestFactory`, `httpClient`, and `randomFactory`. |
||
61 | 28 | * Individual providers may introduce more collaborators, as needed. |
|
62 | */ |
||
63 | 28 | public function __construct(array $options = [], array $collaborators = []) |
|
71 | |||
72 | /** |
||
73 | * Attempts to decrypt the given response. |
||
74 | * |
||
75 | * @param string|array|null $response |
||
76 | * |
||
77 | 6 | * @return string|array|null |
|
78 | */ |
||
79 | 6 | public function decryptResponse($response) |
|
100 | |||
101 | /** |
||
102 | * Get authorization url to begin OAuth flow |
||
103 | * |
||
104 | 6 | * @return string |
|
105 | */ |
||
106 | 6 | public function getBaseAuthorizationUrl() |
|
110 | |||
111 | /** |
||
112 | * Get access token url to retrieve token |
||
113 | * |
||
114 | * @param array $params |
||
115 | * |
||
116 | 12 | * @return string |
|
117 | */ |
||
118 | 12 | public function getBaseAccessTokenUrl(array $params) |
|
122 | |||
123 | /** |
||
124 | * Get provider url to fetch user details |
||
125 | * |
||
126 | * @param AccessToken $token |
||
127 | * |
||
128 | 6 | * @return string |
|
129 | */ |
||
130 | 6 | public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
134 | |||
135 | /** |
||
136 | * Get provider url to fetch introspect token |
||
137 | * |
||
138 | * @param AccessToken $token |
||
139 | 2 | * |
|
140 | * @return string |
||
141 | 2 | */ |
|
142 | 2 | public function getIntrospectTokenUrl(AccessToken $token) |
|
146 | |||
147 | /** |
||
148 | * Builds the logout URL. |
||
149 | * |
||
150 | * @param array $options |
||
151 | * @return string Authorization URL |
||
152 | 2 | */ |
|
153 | public function getLogoutUrl(array $options = []) |
||
160 | |||
161 | /** |
||
162 | 20 | * Get logout url to logout of session token |
|
163 | * |
||
164 | 20 | * @return string |
|
165 | */ |
||
166 | private function getBaseLogoutUrl() |
||
170 | |||
171 | private function fetchIntrospectToken(AccessToken $token) { |
||
187 | |||
188 | 10 | /** |
|
189 | * Creates base url from provider configuration. |
||
190 | 10 | * |
|
191 | 2 | * @return string |
|
192 | 2 | */ |
|
193 | protected function getBaseUrlWithRealm() |
||
197 | |||
198 | /** |
||
199 | * Get the default scopes used by this provider. |
||
200 | * |
||
201 | * This should not be a complete list of all scopes, but the minimum |
||
202 | * required for the provider user interface! |
||
203 | 4 | * |
|
204 | * @return string[] |
||
205 | 4 | */ |
|
206 | protected function getDefaultScopes() |
||
210 | |||
211 | /** |
||
212 | * Check a provider response for errors. |
||
213 | * |
||
214 | 6 | * @throws IdentityProviderException |
|
215 | * @param ResponseInterface $response |
||
216 | 6 | * @param string $data Parsed response data |
|
217 | * @return void |
||
218 | 6 | */ |
|
219 | protected function checkResponse(ResponseInterface $response, $data) |
||
226 | |||
227 | /** |
||
228 | * Generate a user object from a successful user details request. |
||
229 | * |
||
230 | 4 | * @param array $response |
|
231 | * @param AccessToken $token |
||
232 | 4 | * @return KeycloakResourceOwner |
|
233 | */ |
||
234 | 4 | protected function createResourceOwner(array $response, AccessToken $token) |
|
238 | |||
239 | /** |
||
240 | * Requests and returns the resource owner of given access token. |
||
241 | * |
||
242 | * @param AccessToken $token |
||
243 | * @return KeycloakResourceOwner |
||
244 | 4 | */ |
|
245 | public function getResourceOwner(AccessToken $token) |
||
253 | |||
254 | /** |
||
255 | * Requests and returns the resource owner of given access token introspection. |
||
256 | * |
||
257 | * @param AccessToken $token |
||
258 | * @return KeycloakResourceOwner |
||
259 | 4 | */ |
|
260 | public function getResourceOwnerFromIntrospectedToken(AccessToken $token) |
||
268 | |||
269 | /** |
||
270 | * Updates expected encryption algorithm of Keycloak instance. |
||
271 | * |
||
272 | * @param string $encryptionAlgorithm |
||
273 | * |
||
274 | * @return Keycloak |
||
275 | 4 | */ |
|
276 | public function setEncryptionAlgorithm($encryptionAlgorithm) |
||
282 | |||
283 | /** |
||
284 | * Updates expected encryption key of Keycloak instance. |
||
285 | * |
||
286 | * @param string $encryptionKey |
||
287 | * |
||
288 | * @return Keycloak |
||
289 | */ |
||
290 | public function setEncryptionKey($encryptionKey) |
||
296 | |||
297 | /** |
||
298 | * Updates expected encryption key of Keycloak instance to content of given |
||
299 | * file path. |
||
300 | * |
||
301 | * @param string $encryptionKeyPath |
||
302 | * |
||
303 | * @return Keycloak |
||
304 | */ |
||
305 | public function setEncryptionKeyPath($encryptionKeyPath) |
||
315 | |||
316 | /** |
||
317 | * Checks if provider is configured to use encryption. |
||
318 | * |
||
319 | * @return bool |
||
320 | */ |
||
321 | public function usesEncryption() |
||
325 | } |
||
326 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.