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); String code = parameters.getFirst(SmsParameterNames.CODE);
if (StrUtil.isBlank(verifyCode)) { if (StrUtil.isBlank(code)) {
OAuth2EndpointUtils.throwError( OAuth2EndpointUtils.throwError(
OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ErrorCodes.INVALID_REQUEST,
SmsParameterNames.VERIFY_CODE, SmsParameterNames.CODE,
OAuth2EndpointUtils.ACCESS_TOKEN_REQUEST_ERROR_URI); OAuth2EndpointUtils.ACCESS_TOKEN_REQUEST_ERROR_URI);
} }

View File

@ -86,13 +86,13 @@ public class SmsAuthenticationProvider implements AuthenticationProvider {
// 短信验证码校验 // 短信验证码校验
Map<String, Object> additionalParameters = smsAuthenticationToken.getAdditionalParameters(); Map<String, Object> additionalParameters = smsAuthenticationToken.getAdditionalParameters();
String mobile = (String) additionalParameters.get(SmsParameterNames.MOBILE); 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 codeKey = RedisConstants.LOGIN_SMS_CODE_PREFIX + mobile;
String cacheCode = (String) redisTemplate.opsForValue().get(codeKey); String cacheCode = (String) redisTemplate.opsForValue().get(codeKey);
if (!StrUtil.equals(verifyCode, cacheCode)) { if (!StrUtil.equals(code, cacheCode)) {
throw new OAuth2AuthenticationException("验证码错误"); 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() { private SmsParameterNames() {

View File

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