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) |
|
110 | |||
111 | /** |
||
112 | * Get authorization url to begin OAuth flow |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 6 | public function getBaseAuthorizationUrl() |
|
120 | |||
121 | /** |
||
122 | * Get access token url to retrieve token |
||
123 | * |
||
124 | * @param array $params |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | 14 | public function getBaseAccessTokenUrl(array $params) |
|
132 | |||
133 | /** |
||
134 | * Get provider url to fetch user details |
||
135 | * |
||
136 | * @param AccessToken $token |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | 6 | public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
144 | |||
145 | /** |
||
146 | * Creates base url from provider configuration. |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | 18 | protected function getBaseUrlWithRealm() |
|
154 | |||
155 | /** |
||
156 | * Get the default scopes used by this provider. |
||
157 | * |
||
158 | * This should not be a complete list of all scopes, but the minimum |
||
159 | * required for the provider user interface! |
||
160 | * |
||
161 | * @return string[] |
||
162 | */ |
||
163 | 4 | protected function getDefaultScopes() |
|
167 | |||
168 | /** |
||
169 | * Check a provider response for errors. |
||
170 | * |
||
171 | * @throws IdentityProviderException |
||
172 | * @param ResponseInterface $response |
||
173 | * @param string $data Parsed response data |
||
174 | * @return void |
||
175 | */ |
||
176 | 10 | protected function checkResponse(ResponseInterface $response, $data) |
|
183 | |||
184 | /** |
||
185 | * Generate a user object from a successful user details request. |
||
186 | * |
||
187 | * @param array $response |
||
188 | * @param AccessToken $token |
||
189 | * @return KeycloakResourceOwner |
||
190 | */ |
||
191 | 4 | protected function createResourceOwner(array $response, AccessToken $token) |
|
195 | |||
196 | /** |
||
197 | * Requests and returns the resource owner of given access token. |
||
198 | * |
||
199 | * @param AccessToken $token |
||
200 | * @return KeycloakResourceOwner |
||
201 | */ |
||
202 | 6 | public function getResourceOwner(AccessToken $token) |
|
210 | |||
211 | /** |
||
212 | * Updates expected encryption algorithm of Keycloak instance. |
||
213 | * |
||
214 | * @param string $encryptionAlgorithm |
||
215 | * |
||
216 | * @return Keycloak |
||
217 | */ |
||
218 | 4 | public function setEncryptionAlgorithm($encryptionAlgorithm) |
|
224 | |||
225 | /** |
||
226 | * Updates expected encryption key of Keycloak instance. |
||
227 | * |
||
228 | * @param string $encryptionKey |
||
229 | * |
||
230 | * @return Keycloak |
||
231 | */ |
||
232 | 4 | public function setEncryptionKey($encryptionKey) |
|
238 | |||
239 | /** |
||
240 | * Updates expected encryption key of Keycloak instance to content of given |
||
241 | * file path. |
||
242 | * |
||
243 | * @param string $encryptionKeyPath |
||
244 | * |
||
245 | * @return Keycloak |
||
246 | */ |
||
247 | 2 | public function setEncryptionKeyPath($encryptionKeyPath) |
|
257 | } |
||
258 |
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.