Skip to content

Commit 3c297de

Browse files
committed
Add ID token support for token exchange
Introduce support for exchanging externally-issued OIDC ID tokens for access tokens via the OAuth 2.0 Token Exchange Grant per RFC 8693 Section 3. - Add urn:ietf:params:oauth:token-type:id_token as a supported token type in the converter - Add OAuth2TokenExchangeSubjectTokenResolver strategy interface for resolving external subject tokens - Add OidcIdTokenSubjectTokenResolver as the default implementation using JwtDecoderFactory - Modify OAuth2TokenExchangeAuthenticationProvider to delegate to the resolver before falling back to the authorization service - Auto-wire the resolver bean in the configurer Closes gh-19048 Signed-off-by: Bapuji Koraganti <bapuk.2008@gmail.com>
1 parent 1455798 commit 3c297de

32 files changed

Lines changed: 1649 additions & 343 deletions

File tree

config/src/main/java/org/springframework/security/config/annotation/web/configurers/WebAuthnConfigurer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2525
import org.springframework.context.ApplicationContext;
2626
import org.springframework.http.converter.HttpMessageConverter;
27+
import org.springframework.security.authentication.AuthenticationEventPublisher;
2728
import org.springframework.security.authentication.ProviderManager;
2829
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
2930
import org.springframework.security.core.authority.FactorGrantedAuthority;
@@ -176,8 +177,10 @@ public void configure(H http) {
176177
WebAuthnRelyingPartyOperations rpOperations = webAuthnRelyingPartyOperations(userEntities, userCredentials);
177178
PublicKeyCredentialCreationOptionsRepository creationOptionsRepository = creationOptionsRepository();
178179
WebAuthnAuthenticationFilter webAuthnAuthnFilter = new WebAuthnAuthenticationFilter();
179-
webAuthnAuthnFilter.setAuthenticationManager(
180-
new ProviderManager(new WebAuthnAuthenticationProvider(rpOperations, userDetailsService)));
180+
ProviderManager providerManager = new ProviderManager(
181+
new WebAuthnAuthenticationProvider(rpOperations, userDetailsService));
182+
getBeanOrNull(AuthenticationEventPublisher.class).ifPresent(providerManager::setAuthenticationEventPublisher);
183+
webAuthnAuthnFilter.setAuthenticationManager(providerManager);
181184
webAuthnAuthnFilter = postProcess(webAuthnAuthnFilter);
182185
WebAuthnRegistrationFilter webAuthnRegistrationFilter = new WebAuthnRegistrationFilter(userCredentials,
183186
rpOperations);

config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/authorization/OAuth2TokenEndpointConfigurer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2DeviceCodeAuthenticationProvider;
4141
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2RefreshTokenAuthenticationProvider;
4242
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2TokenExchangeAuthenticationProvider;
43+
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2TokenExchangeSubjectTokenResolver;
4344
import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings;
4445
import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenGenerator;
4546
import org.springframework.security.oauth2.server.authorization.web.OAuth2TokenEndpointFilter;
@@ -271,6 +272,11 @@ private static List<AuthenticationProvider> createDefaultAuthenticationProviders
271272

272273
OAuth2TokenExchangeAuthenticationProvider tokenExchangeAuthenticationProvider = new OAuth2TokenExchangeAuthenticationProvider(
273274
authorizationService, tokenGenerator);
275+
OAuth2TokenExchangeSubjectTokenResolver subjectTokenResolver = OAuth2ConfigurerUtils
276+
.getOptionalBean(httpSecurity, OAuth2TokenExchangeSubjectTokenResolver.class);
277+
if (subjectTokenResolver != null) {
278+
tokenExchangeAuthenticationProvider.setSubjectTokenResolver(subjectTokenResolver);
279+
}
274280
authenticationProviders.add(tokenExchangeAuthenticationProvider);
275281

276282
return authenticationProviders;

config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/resource/DPoPAuthenticationConfigurer.java

Lines changed: 0 additions & 239 deletions
This file was deleted.

0 commit comments

Comments
 (0)