1616
1717package org .springframework .security .config .annotation .web .configurers .oauth2 .client ;
1818
19+ import com .nimbusds .jose .JOSEObjectType ;
20+ import com .nimbusds .jose .proc .DefaultJOSEObjectTypeVerifier ;
21+ import com .nimbusds .jose .proc .JOSEObjectTypeVerifier ;
22+ import com .nimbusds .jose .proc .SecurityContext ;
23+
1924import org .springframework .security .authentication .AuthenticationProvider ;
2025import org .springframework .security .authentication .AuthenticationServiceException ;
2126import org .springframework .security .core .Authentication ;
2631import org .springframework .security .oauth2 .core .OAuth2AuthenticationException ;
2732import org .springframework .security .oauth2 .core .OAuth2Error ;
2833import org .springframework .security .oauth2 .core .OAuth2ErrorCodes ;
34+ import org .springframework .security .oauth2 .core .converter .ClaimTypeConverter ;
2935import org .springframework .security .oauth2 .jwt .BadJwtException ;
3036import org .springframework .security .oauth2 .jwt .Jwt ;
3137import org .springframework .security .oauth2 .jwt .JwtDecoder ;
3238import org .springframework .security .oauth2 .jwt .JwtDecoderFactory ;
39+ import org .springframework .security .oauth2 .jwt .NimbusJwtDecoder ;
3340import org .springframework .util .Assert ;
41+ import org .springframework .util .StringUtils ;
3442
3543/**
3644 * An {@link AuthenticationProvider} that authenticates an OIDC Logout Token; namely
@@ -56,9 +64,27 @@ final class OidcBackChannelLogoutAuthenticationProvider implements Authenticatio
5664 * Construct an {@link OidcBackChannelLogoutAuthenticationProvider}
5765 */
5866 OidcBackChannelLogoutAuthenticationProvider () {
59- OidcIdTokenDecoderFactory logoutTokenDecoderFactory = new OidcIdTokenDecoderFactory ();
60- logoutTokenDecoderFactory .setJwtValidatorFactory (new DefaultOidcLogoutTokenValidatorFactory ());
61- this .logoutTokenDecoderFactory = logoutTokenDecoderFactory ;
67+ DefaultOidcLogoutTokenValidatorFactory jwtValidator = new DefaultOidcLogoutTokenValidatorFactory ();
68+ this .logoutTokenDecoderFactory = (clientRegistration ) -> {
69+ String jwkSetUri = clientRegistration .getProviderDetails ().getJwkSetUri ();
70+ if (!StringUtils .hasText (jwkSetUri )) {
71+ OAuth2Error oauth2Error = new OAuth2Error ("missing_signature_verifier" ,
72+ "Failed to find a Signature Verifier for Client Registration: '"
73+ + clientRegistration .getRegistrationId ()
74+ + "'. Check to ensure you have configured the JwkSet URI." ,
75+ null );
76+ throw new OAuth2AuthenticationException (oauth2Error , oauth2Error .toString ());
77+ }
78+ JOSEObjectTypeVerifier <SecurityContext > typeVerifier = new DefaultJOSEObjectTypeVerifier <>(null ,
79+ JOSEObjectType .JWT , new JOSEObjectType ("logout+jwt" ));
80+ NimbusJwtDecoder decoder = NimbusJwtDecoder .withJwkSetUri (jwkSetUri )
81+ .jwtProcessorCustomizer ((processor ) -> processor .setJWSTypeVerifier (typeVerifier ))
82+ .build ();
83+ decoder .setJwtValidator (jwtValidator .apply (clientRegistration ));
84+ decoder .setClaimSetConverter (
85+ new ClaimTypeConverter (OidcIdTokenDecoderFactory .createDefaultClaimTypeConverters ()));
86+ return decoder ;
87+ };
6288 }
6389
6490 /**
0 commit comments