fix: 短信验证码的参数名称修改

This commit is contained in:
hxr 2024-03-05 00:23:59 +08:00
parent 7be21be8d6
commit ba7a543eb0
4 changed files with 8 additions and 8 deletions

View File

@ -66,11 +66,11 @@ public class SmsAuthenticationConverter implements AuthenticationConverter {
}
// 验证码(必需)
String verifyCode = parameters.getFirst(SmsParameterNames.VERIFY_CODE);
if (StrUtil.isBlank(verifyCode)) {
String code = parameters.getFirst(SmsParameterNames.CODE);
if (StrUtil.isBlank(code)) {
OAuth2EndpointUtils.throwError(
OAuth2ErrorCodes.INVALID_REQUEST,
SmsParameterNames.VERIFY_CODE,
SmsParameterNames.CODE,
OAuth2EndpointUtils.ACCESS_TOKEN_REQUEST_ERROR_URI);
}

View File

@ -86,13 +86,13 @@ public class SmsAuthenticationProvider implements AuthenticationProvider {
// 短信验证码校验
Map<String, Object> additionalParameters = smsAuthenticationToken.getAdditionalParameters();
String mobile = (String) additionalParameters.get(SmsParameterNames.MOBILE);
String verifyCode = (String) additionalParameters.get(SmsParameterNames.VERIFY_CODE);
String code = (String) additionalParameters.get(SmsParameterNames.CODE);
if (!verifyCode.equals("666666")) { // 666666 是后门因为短信收费正式环境删除这个if
if (!code.equals("666666")) { // 666666 是后门因为短信收费正式环境删除这个if
String codeKey = RedisConstants.LOGIN_SMS_CODE_PREFIX + mobile;
String cacheCode = (String) redisTemplate.opsForValue().get(codeKey);
if (!StrUtil.equals(verifyCode, cacheCode)) {
if (!StrUtil.equals(code, cacheCode)) {
throw new OAuth2AuthenticationException("验证码错误");
}
}

View File

@ -32,7 +32,7 @@ public final class SmsParameterNames {
/**
* 验证码
*/
public static final String VERIFY_CODE = "verifyCode";
public static final String CODE = "code";
private SmsParameterNames() {

View File

@ -32,7 +32,7 @@ public class SmsAuthenticationTests {
this.mvc.perform(post("/oauth2/token")
.param(OAuth2ParameterNames.GRANT_TYPE, "sms_code")
.param("mobile", "18866668888")
.param("verifyCode", "666666")
.param("code", "666666")
.headers(headers))
.andDo(print())
.andExpect(status().isOk())