Skip to content

Commit 2bb0781

Browse files
committed
fix: only use the prompt param for the authorization and token endpoints if defined in NC config, drop 'consent' as the defaut
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent f1f18a3 commit 2bb0781

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

‎lib/Controller/LoginController.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ public function login(int $providerId, ?string $redirectUrl = null) {
270270
'claims' => json_encode($claims),
271271
'state' => $state,
272272
'nonce' => $nonce,
273-
'prompt' => $oidcConfig['prompt'] ?? 'consent'
274273
];
275274

275+
if ($oidcConfig['prompt']) {
276+
$data['prompt'] = $oidcConfig['prompt'];
277+
}
276278

277279
if ($isPkceEnabled) {
278280
$data['code_challenge'] = $this->toCodeChallenge($code_verifier);

‎lib/Service/TokenService.php‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,28 @@ public function getExchangedToken(string $targetAudience, array $extraScopes = [
255255
}
256256
}
257257
$this->logger->debug('[TokenService] Exchanging the token: ' . $discovery['token_endpoint']);
258+
$tokenEndpointParams = [
259+
'client_id' => $oidcProvider->getClientId(),
260+
'client_secret' => $clientSecret,
261+
'grant_type' => 'urn:ietf:params:oauth:grant-type:token-exchange',
262+
'subject_token' => $loginToken->getAccessToken(),
263+
'subject_token_type' => 'urn:ietf:params:oauth:token-type:access_token',
264+
// can also be
265+
// urn:ietf:params:oauth:token-type:access_token
266+
// or urn:ietf:params:oauth:token-type:id_token
267+
// this one will get us an access token and refresh token within the response
268+
'requested_token_type' => 'urn:ietf:params:oauth:token-type:refresh_token',
269+
'audience' => $targetAudience,
270+
'scope' => $scope,
271+
];
272+
if ($this->config->getSystemValue('user_oidc.prompt') !== '') {
273+
// none, consent, login and internal for oauth2 passport server
274+
$tokenEndpointParams['prompt'] = $this->config->getSystemValue('user_oidc.prompt');
275+
}
258276
// more in https://www.keycloak.org/securing-apps/token-exchange
259277
$body = $this->clientService->post(
260278
$discovery['token_endpoint'],
261-
[
262-
'client_id' => $oidcProvider->getClientId(),
263-
'client_secret' => $clientSecret,
264-
'grant_type' => 'urn:ietf:params:oauth:grant-type:token-exchange',
265-
'subject_token' => $loginToken->getAccessToken(),
266-
'subject_token_type' => 'urn:ietf:params:oauth:token-type:access_token',
267-
// can also be
268-
// urn:ietf:params:oauth:token-type:access_token
269-
// or urn:ietf:params:oauth:token-type:id_token
270-
// this one will get us an access token and refresh token within the response
271-
'requested_token_type' => 'urn:ietf:params:oauth:token-type:refresh_token',
272-
'audience' => $targetAudience,
273-
'scope' => $scope,
274-
'prompt' => $this->config->getSystemValue('user_oidc.prompt', 'consent') // none,consent,login and internal for oauth2 passport server
275-
]
279+
$tokenEndpointParams,
276280
);
277281
$this->logger->debug('[TokenService] Token exchange request params', [
278282
'client_id' => $oidcProvider->getClientId(),

0 commit comments

Comments
 (0)