@@ -255,24 +255,29 @@ 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+ $ oidcConfig = $ this ->config ->getSystemValue ('user_oidc ' , []);
273+ if (isset ($ oidcConfig ['prompt ' ]) && is_string ($ oidcConfig ['prompt ' ])) {
274+ // none, consent, login and internal for oauth2 passport server
275+ $ tokenEndpointParams ['prompt ' ] = $ oidcConfig ['prompt ' ];
276+ }
258277 // more in https://www.keycloak.org/securing-apps/token-exchange
259278 $ body = $ this ->clientService ->post (
260279 $ 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- ]
280+ $ tokenEndpointParams ,
276281 );
277282 $ this ->logger ->debug ('[TokenService] Token exchange request params ' , [
278283 'client_id ' => $ oidcProvider ->getClientId (),
0 commit comments