1 | <?php |
||
14 | class Keycloak extends AbstractProvider |
||
15 | { |
||
16 | use BearerAuthorizationTrait; |
||
17 | |||
18 | /** |
||
19 | * Keycloak URL, eg. http://localhost:8080/auth. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | public $authServerUrl = null; |
||
24 | |||
25 | /** |
||
26 | * Realm name, eg. demo. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | public $realm = null; |
||
31 | |||
32 | /** |
||
33 | * Encryption algorithm. |
||
34 | * |
||
35 | * You must specify supported algorithms for your application. See |
||
36 | * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40 |
||
37 | * for a list of spec-compliant algorithms. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | public $encryptionAlgorithm = null; |
||
42 | |||
43 | /** |
||
44 | * Encryption key. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | public $encryptionKey = null; |
||
49 | |||
50 | /** |
||
51 | * Constructs an OAuth 2.0 service provider. |
||
52 | * |
||
53 | * @param array $options An array of options to set on this provider. |
||
54 | * Options include `clientId`, `clientSecret`, `redirectUri`, and `state`. |
||
55 | * Individual providers may introduce more options, as needed. |
||
56 | * @param array $collaborators An array of collaborators that may be used to |
||
57 | * override this provider's default behavior. Collaborators include |
||
58 | * `grantFactory`, `requestFactory`, `httpClient`, and `randomFactory`. |
||
59 | * Individual providers may introduce more collaborators, as needed. |
||
60 | */ |
||
61 | 28 | public function __construct(array $options = [], array $collaborators = []) |
|
69 | |||
70 | /** |
||
71 | * Attempts to decrypt the given response. |
||
72 | * |
||
73 | * @param string|array|null $response |
||
74 | * |
||
75 | * @return string|array|null |
||
76 | */ |
||
77 | 6 | public function decryptResponse($response) |
|
98 | |||
99 | /** |
||
100 | * Get authorization url to begin OAuth flow |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 6 | public function getBaseAuthorizationUrl() |
|
108 | |||
109 | /** |
||
110 | * Get access token url to retrieve token |
||
111 | * |
||
112 | * @param array $params |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 12 | public function getBaseAccessTokenUrl(array $params) |
|
120 | |||
121 | /** |
||
122 | * Get provider url to fetch user details |
||
123 | * |
||
124 | * @param AccessToken $token |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | 6 | public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
132 | |||
133 | /** |
||
134 | * Builds the logout URL. |
||
135 | * |
||
136 | * @param array $options |
||
137 | * @return string Authorization URL |
||
138 | */ |
||
139 | 2 | public function getLogoutUrl(array $options = []) |
|
146 | |||
147 | /** |
||
148 | * Get logout url to logout of session token |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | 2 | private function getBaseLogoutUrl() |
|
156 | |||
157 | /** |
||
158 | * Creates base url from provider configuration. |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | 20 | protected function getBaseUrlWithRealm() |
|
166 | |||
167 | /** |
||
168 | * Get the default scopes used by this provider. |
||
169 | * |
||
170 | * This should not be a complete list of all scopes, but the minimum |
||
171 | * required for the provider user interface! |
||
172 | * |
||
173 | * @return string[] |
||
174 | */ |
||
175 | 6 | protected function getDefaultScopes() |
|
179 | |||
180 | /** |
||
181 | * Check a provider response for errors. |
||
182 | * |
||
183 | * @throws IdentityProviderException |
||
184 | * @param ResponseInterface $response |
||
185 | * @param string $data Parsed response data |
||
186 | * @return void |
||
187 | */ |
||
188 | 10 | protected function checkResponse(ResponseInterface $response, $data) |
|
195 | |||
196 | /** |
||
197 | * Generate a user object from a successful user details request. |
||
198 | * |
||
199 | * @param array $response |
||
200 | * @param AccessToken $token |
||
201 | * @return KeycloakResourceOwner |
||
202 | */ |
||
203 | 4 | protected function createResourceOwner(array $response, AccessToken $token) |
|
207 | |||
208 | /** |
||
209 | * Requests and returns the resource owner of given access token. |
||
210 | * |
||
211 | * @param AccessToken $token |
||
212 | * @return KeycloakResourceOwner |
||
213 | */ |
||
214 | 6 | public function getResourceOwner(AccessToken $token) |
|
222 | |||
223 | /** |
||
224 | * Updates expected encryption algorithm of Keycloak instance. |
||
225 | * |
||
226 | * @param string $encryptionAlgorithm |
||
227 | * |
||
228 | * @return Keycloak |
||
229 | */ |
||
230 | 4 | public function setEncryptionAlgorithm($encryptionAlgorithm) |
|
236 | |||
237 | /** |
||
238 | * Updates expected encryption key of Keycloak instance. |
||
239 | * |
||
240 | * @param string $encryptionKey |
||
241 | * |
||
242 | * @return Keycloak |
||
243 | */ |
||
244 | 4 | public function setEncryptionKey($encryptionKey) |
|
250 | |||
251 | /** |
||
252 | * Updates expected encryption key of Keycloak instance to content of given |
||
253 | * file path. |
||
254 | * |
||
255 | * @param string $encryptionKeyPath |
||
256 | * |
||
257 | * @return Keycloak |
||
258 | */ |
||
259 | 4 | public function setEncryptionKeyPath($encryptionKeyPath) |
|
269 | |||
270 | /** |
||
271 | * Checks if provider is configured to use encryption. |
||
272 | * |
||
273 | * @return bool |
||
274 | */ |
||
275 | 4 | public function usesEncryption() |
|
279 | } |
||
280 |
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.