Skip to content

Commit c15b299

Browse files
committed
Allow at+jwt, according to RFC-9068
Closes 13185
1 parent 01c8a22 commit c15b299

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoders.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.Map;
2020

21+
import com.nimbusds.jose.JOSEObjectType;
22+
import com.nimbusds.jose.proc.DefaultJOSEObjectTypeVerifier;
2123
import org.springframework.security.oauth2.core.OAuth2TokenValidator;
2224
import org.springframework.util.Assert;
2325

@@ -111,7 +113,16 @@ private static JwtDecoder withProviderConfiguration(Map<String, Object> configur
111113
OAuth2TokenValidator<Jwt> jwtValidator = JwtValidators.createDefaultWithIssuer(issuer);
112114
String jwkSetUri = configuration.get("jwks_uri").toString();
113115
NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withJwkSetUri(jwkSetUri)
114-
.jwtProcessorCustomizer(JwtDecoderProviderConfigurationUtils::addJWSAlgorithms).build();
116+
.jwtProcessorCustomizer(customizer -> {
117+
customizer.setJWSTypeVerifier(new DefaultJOSEObjectTypeVerifier<>(
118+
new JOSEObjectType("jwt"), // for compatibility
119+
new JOSEObjectType("application/at+jwt"), // according to RFC-9068
120+
new JOSEObjectType("at+jwt"), // according to RFC-9068
121+
null
122+
));
123+
JwtDecoderProviderConfigurationUtils.addJWSAlgorithms(customizer);
124+
})
125+
.build();
115126
jwtDecoder.setJwtValidator(jwtValidator);
116127
return jwtDecoder;
117128
}

oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtValidators.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616

1717
package org.springframework.security.oauth2.jwt;
1818

19-
import java.util.ArrayList;
20-
import java.util.Arrays;
21-
import java.util.List;
22-
2319
import org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator;
2420
import org.springframework.security.oauth2.core.OAuth2TokenValidator;
2521

@@ -50,10 +46,9 @@ private JwtValidators() {
5046
* supplied
5147
*/
5248
public static OAuth2TokenValidator<Jwt> createDefaultWithIssuer(String issuer) {
53-
List<OAuth2TokenValidator<Jwt>> validators = new ArrayList<>();
54-
validators.add(new JwtTimestampValidator());
55-
validators.add(new JwtIssuerValidator(issuer));
56-
return new DelegatingOAuth2TokenValidator<>(validators);
49+
JwtTimestampValidator jwtTimestampValidator = new JwtTimestampValidator();
50+
JwtIssuerValidator jwtIssuerValidator = new JwtIssuerValidator(issuer);
51+
return new DelegatingOAuth2TokenValidator<>(jwtTimestampValidator, jwtIssuerValidator);
5752
}
5853

5954
/**
@@ -69,7 +64,7 @@ public static OAuth2TokenValidator<Jwt> createDefaultWithIssuer(String issuer) {
6964
* supplied
7065
*/
7166
public static OAuth2TokenValidator<Jwt> createDefault() {
72-
return new DelegatingOAuth2TokenValidator<>(Arrays.asList(new JwtTimestampValidator()));
67+
return new DelegatingOAuth2TokenValidator<>(new JwtTimestampValidator());
7368
}
7469

7570
}

0 commit comments

Comments
 (0)