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 | 24 | 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) |
|
102 | |||
103 | /** |
||
104 | * Get authorization url to begin OAuth flow |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | 6 | public function getBaseAuthorizationUrl() |
|
112 | |||
113 | /** |
||
114 | * Get access token url to retrieve token |
||
115 | * |
||
116 | * @param array $params |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | 12 | public function getBaseAccessTokenUrl(array $params) |
|
124 | |||
125 | /** |
||
126 | * Get provider url to fetch user details |
||
127 | * |
||
128 | * @param AccessToken $token |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | 6 | public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
136 | |||
137 | /** |
||
138 | * Creates base url from provider configuration. |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | 18 | protected function getBaseUrlWithRealm() |
|
146 | |||
147 | /** |
||
148 | * Get the default scopes used by this provider. |
||
149 | * |
||
150 | * This should not be a complete list of all scopes, but the minimum |
||
151 | * required for the provider user interface! |
||
152 | * |
||
153 | * @return string[] |
||
154 | */ |
||
155 | 4 | protected function getDefaultScopes() |
|
159 | |||
160 | /** |
||
161 | * Check a provider response for errors. |
||
162 | * |
||
163 | * @throws IdentityProviderException |
||
164 | * @param ResponseInterface $response |
||
165 | * @param string $data Parsed response data |
||
166 | * @return void |
||
167 | */ |
||
168 | 10 | protected function checkResponse(ResponseInterface $response, $data) |
|
175 | |||
176 | /** |
||
177 | * Generate a user object from a successful user details request. |
||
178 | * |
||
179 | * @param array $response |
||
180 | * @param AccessToken $token |
||
181 | * @return KeycloakResourceOwner |
||
182 | */ |
||
183 | 4 | protected function createResourceOwner(array $response, AccessToken $token) |
|
187 | |||
188 | /** |
||
189 | * Requests and returns the resource owner of given access token. |
||
190 | * |
||
191 | * @param AccessToken $token |
||
192 | * @return KeycloakResourceOwner |
||
193 | */ |
||
194 | 6 | public function getResourceOwner(AccessToken $token) |
|
202 | |||
203 | /** |
||
204 | * Updates expected encryption algorithm of Keycloak instance. |
||
205 | * |
||
206 | * @param string $encryptionAlgorithm |
||
207 | * |
||
208 | * @return Keycloak |
||
209 | */ |
||
210 | 4 | public function setEncryptionAlgorithm($encryptionAlgorithm) |
|
216 | |||
217 | /** |
||
218 | * Updates expected encryption key of Keycloak instance. |
||
219 | * |
||
220 | * @param string $encryptionKey |
||
221 | * |
||
222 | * @return Keycloak |
||
223 | */ |
||
224 | 4 | public function setEncryptionKey($encryptionKey) |
|
230 | |||
231 | /** |
||
232 | * Updates expected encryption key of Keycloak instance to content of given |
||
233 | * file path. |
||
234 | * |
||
235 | * @param string $encryptionKeyPath |
||
236 | * |
||
237 | * @return Keycloak |
||
238 | */ |
||
239 | 2 | public function setEncryptionKeyPath($encryptionKeyPath) |
|
249 | } |
||
250 |
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.