1 | <?php |
||
15 | class Keycloak extends AbstractProvider |
||
16 | { |
||
17 | use BearerAuthorizationTrait; |
||
18 | |||
19 | /** |
||
20 | * Keycloak URL, eg. http://localhost:8080/auth. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | public $authServerUrl = null; |
||
25 | |||
26 | /** |
||
27 | * Realm name, eg. demo. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | public $realm = null; |
||
32 | |||
33 | /** |
||
34 | * Encryption algorithm. |
||
35 | * |
||
36 | * You must specify supported algorithms for your application. See |
||
37 | * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40 |
||
38 | * for a list of spec-compliant algorithms. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | public $encryptionAlgorithm = null; |
||
43 | |||
44 | /** |
||
45 | * Encryption key. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | public $encryptionKey = null; |
||
50 | |||
51 | /** |
||
52 | * Constructs an OAuth 2.0 service provider. |
||
53 | * |
||
54 | * @param array $options An array of options to set on this provider. |
||
55 | * Options include `clientId`, `clientSecret`, `redirectUri`, and `state`. |
||
56 | * Individual providers may introduce more options, as needed. |
||
57 | * @param array $collaborators An array of collaborators that may be used to |
||
58 | * override this provider's default behavior. Collaborators include |
||
59 | * `grantFactory`, `requestFactory`, `httpClient`, and `randomFactory`. |
||
60 | * Individual providers may introduce more collaborators, as needed. |
||
61 | 28 | */ |
|
62 | public function __construct(array $options = [], array $collaborators = []) |
||
70 | |||
71 | /** |
||
72 | * Attempts to decrypt the given response. |
||
73 | * |
||
74 | * @param string|array|null $response |
||
75 | * |
||
76 | * @return string|array|null |
||
77 | 6 | */ |
|
78 | public function decryptResponse($response) |
||
99 | |||
100 | /** |
||
101 | * Get authorization url to begin OAuth flow |
||
102 | * |
||
103 | * @return string |
||
104 | 6 | */ |
|
105 | public function getBaseAuthorizationUrl() |
||
109 | |||
110 | /** |
||
111 | * Get access token url to retrieve token |
||
112 | * |
||
113 | * @param array $params |
||
114 | * |
||
115 | * @return string |
||
116 | 12 | */ |
|
117 | public function getBaseAccessTokenUrl(array $params) |
||
121 | |||
122 | /** |
||
123 | * Get provider url to fetch user details |
||
124 | * |
||
125 | * @param AccessToken $token |
||
126 | * |
||
127 | * @return string |
||
128 | 6 | */ |
|
129 | public function getResourceOwnerDetailsUrl(AccessToken $token) |
||
133 | |||
134 | /** |
||
135 | * Builds the logout URL. |
||
136 | * |
||
137 | * @param array $options |
||
138 | * @return string Authorization URL |
||
139 | 2 | */ |
|
140 | public function getLogoutUrl(array $options = []) |
||
147 | |||
148 | /** |
||
149 | * Get logout url to logout of session token |
||
150 | * |
||
151 | * @return string |
||
152 | 2 | */ |
|
153 | private function getBaseLogoutUrl() |
||
157 | |||
158 | /** |
||
159 | * Creates base url from provider configuration. |
||
160 | * |
||
161 | * @return string |
||
162 | 20 | */ |
|
163 | protected function getBaseUrlWithRealm() |
||
167 | |||
168 | /** |
||
169 | * Get the default scopes used by this provider. |
||
170 | * |
||
171 | * This should not be a complete list of all scopes, but the minimum |
||
172 | * required for the provider user interface! |
||
173 | * |
||
174 | * @return string[] |
||
175 | 6 | */ |
|
176 | protected function getDefaultScopes() |
||
180 | |||
181 | /** |
||
182 | * Check a provider response for errors. |
||
183 | * |
||
184 | * @throws IdentityProviderException |
||
185 | * @param ResponseInterface $response |
||
186 | * @param string $data Parsed response data |
||
187 | * @return void |
||
188 | 10 | */ |
|
189 | protected function checkResponse(ResponseInterface $response, $data) |
||
196 | |||
197 | /** |
||
198 | * Generate a user object from a successful user details request. |
||
199 | * |
||
200 | * @param array $response |
||
201 | * @param AccessToken $token |
||
202 | * @return KeycloakResourceOwner |
||
203 | 4 | */ |
|
204 | protected function createResourceOwner(array $response, AccessToken $token) |
||
208 | |||
209 | /** |
||
210 | * Requests and returns the resource owner of given access token. |
||
211 | * |
||
212 | * @param AccessToken $token |
||
213 | * @return KeycloakResourceOwner |
||
214 | 6 | * @throws EncryptionConfigurationException |
|
215 | */ |
||
216 | 6 | public function getResourceOwner(AccessToken $token) |
|
230 | 4 | ||
231 | /** |
||
232 | 4 | * Updates expected encryption algorithm of Keycloak instance. |
|
233 | * |
||
234 | 4 | * @param string $encryptionAlgorithm |
|
235 | * |
||
236 | * @return Keycloak |
||
237 | */ |
||
238 | public function setEncryptionAlgorithm($encryptionAlgorithm) |
||
244 | 4 | ||
245 | /** |
||
246 | 4 | * Updates expected encryption key of Keycloak instance. |
|
247 | * |
||
248 | 4 | * @param string $encryptionKey |
|
249 | * |
||
250 | * @return Keycloak |
||
251 | */ |
||
252 | public function setEncryptionKey($encryptionKey) |
||
258 | |||
259 | 4 | /** |
|
260 | * Updates expected encryption key of Keycloak instance to content of given |
||
261 | * file path. |
||
262 | 4 | * |
|
263 | 2 | * @param string $encryptionKeyPath |
|
264 | * |
||
265 | * @return Keycloak |
||
266 | */ |
||
267 | 4 | public function setEncryptionKeyPath($encryptionKeyPath) |
|
277 | 4 | ||
278 | /** |
||
279 | * Checks if provider is configured to use encryption. |
||
280 | * |
||
281 | * @return bool |
||
282 | */ |
||
283 | public function usesEncryption() |
||
287 | |||
288 | /** |
||
289 | * Parses the response according to its content-type header. |
||
290 | * |
||
291 | * @throws UnexpectedValueException |
||
292 | * @param ResponseInterface $response |
||
293 | * @return array |
||
294 | */ |
||
295 | protected function parseResponse(ResponseInterface $response) |
||
313 | } |
||
314 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.