Fix OAuth2 Error Code

Closes gh-10319
This commit is contained in:
Josh Cummings 2021-09-28 13:24:51 -06:00
parent 31cc0b856e
commit dc95d8d705
2 changed files with 3 additions and 1 deletions

View File

@ -95,7 +95,7 @@ public final class JwtTimestampValidator implements OAuth2TokenValidator<Jwt> {
private OAuth2Error createOAuth2Error(String reason) { private OAuth2Error createOAuth2Error(String reason) {
logger.debug(reason); logger.debug(reason);
return new OAuth2Error( return new OAuth2Error(
OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ErrorCodes.INVALID_TOKEN,
reason, reason,
"https://tools.ietf.org/html/rfc6750#section-3.1"); "https://tools.ietf.org/html/rfc6750#section-3.1");
} }

View File

@ -27,6 +27,7 @@ import java.util.stream.Collectors;
import org.junit.Test; import org.junit.Test;
import org.springframework.security.oauth2.core.OAuth2Error; import org.springframework.security.oauth2.core.OAuth2Error;
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult; import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult;
import org.springframework.security.oauth2.jose.jws.JwsAlgorithms; import org.springframework.security.oauth2.jose.jws.JwsAlgorithms;
@ -109,6 +110,7 @@ public class JwtTimestampValidatorTests {
result.getErrors().stream().map(OAuth2Error::getDescription).collect(Collectors.toList()); result.getErrors().stream().map(OAuth2Error::getDescription).collect(Collectors.toList());
assertThat(result.hasErrors()).isTrue(); assertThat(result.hasErrors()).isTrue();
assertThat(result.getErrors().iterator().next().getErrorCode()).isEqualTo(OAuth2ErrorCodes.INVALID_TOKEN);
assertThat(messages).contains("Jwt used before " + justOverOneDayFromNow); assertThat(messages).contains("Jwt used before " + justOverOneDayFromNow);
} }