|
21 | 21 | use OCA\UserOIDC\Event\TokenObtainedEvent; |
22 | 22 | use OCA\UserOIDC\Helper\HttpClientHelper; |
23 | 23 | use OCA\UserOIDC\Service\DiscoveryService; |
| 24 | +use OCA\UserOIDC\Service\JwkService; |
24 | 25 | use OCA\UserOIDC\Service\LdapService; |
25 | 26 | use OCA\UserOIDC\Service\OIDCService; |
26 | 27 | use OCA\UserOIDC\Service\ProviderService; |
@@ -91,6 +92,7 @@ public function __construct( |
91 | 92 | private ICrypto $crypto, |
92 | 93 | private TokenService $tokenService, |
93 | 94 | private OidcService $oidcService, |
| 95 | + private JwkService $jwkService, |
94 | 96 | ) { |
95 | 97 | parent::__construct($request, $config, $l10n); |
96 | 98 | } |
@@ -373,6 +375,7 @@ public function code(string $state = '', string $code = '', string $scope = '', |
373 | 375 | $oidcSystemConfig = $this->config->getSystemValue('user_oidc', []); |
374 | 376 | $isPkceSupported = in_array('S256', $discovery['code_challenge_methods_supported'] ?? [], true); |
375 | 377 | $isPkceEnabled = $isPkceSupported && ($oidcSystemConfig['use_pkce'] ?? true); |
| 378 | + $usePrivateKeyJwt = $this->providerService->getSetting($providerId, ProviderService::SETTING_USE_PRIVATE_KEY_JWT, '0') !== '0'; |
376 | 379 |
|
377 | 380 | try { |
378 | 381 | $requestBody = [ |
@@ -402,15 +405,21 @@ public function code(string $state = '', string $code = '', string $scope = '', |
402 | 405 | $tokenEndpointAuthMethod = 'client_secret_post'; |
403 | 406 | } |
404 | 407 |
|
405 | | - if ($tokenEndpointAuthMethod === 'client_secret_basic') { |
| 408 | + // private key JWT auth does not work with client_secret_basic, we don't wanna pass the client secret |
| 409 | + if ($tokenEndpointAuthMethod === 'client_secret_basic' && !$usePrivateKeyJwt) { |
406 | 410 | $headers = [ |
407 | 411 | 'Authorization' => 'Basic ' . base64_encode($provider->getClientId() . ':' . $providerClientSecret), |
408 | 412 | 'Content-Type' => 'application/x-www-form-urlencoded', |
409 | 413 | ]; |
410 | 414 | } else { |
411 | 415 | // Assuming client_secret_post as no other option is supported currently |
412 | 416 | $requestBody['client_id'] = $provider->getClientId(); |
413 | | - $requestBody['client_secret'] = $providerClientSecret; |
| 417 | + if ($usePrivateKeyJwt) { |
| 418 | + $requestBody['client_assertion_type'] = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'; |
| 419 | + $requestBody['client_assertion'] = $this->jwkService->generateClientAssertion($provider, $discovery['issuer'], $code); |
| 420 | + } else { |
| 421 | + $requestBody['client_secret'] = $providerClientSecret; |
| 422 | + } |
414 | 423 | } |
415 | 424 |
|
416 | 425 | $body = $this->clientService->post( |
|
0 commit comments