diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/IAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/IAuthStrategy.java index 690f74024..81abd325b 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/IAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/IAuthStrategy.java @@ -28,14 +28,14 @@ public interface IAuthStrategy { throw new ServiceException("授权类型不正确!"); } IAuthStrategy instance = SpringUtils.getBean(beanName); - instance.validate(loginBody); + instance.validate(); return instance.login(clientId, loginBody, client); } /** * 参数校验 */ - void validate(LoginBody loginBody); + void validate(); /** * 登录 diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java index edb12c925..6f22cfc5e 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java @@ -2,6 +2,7 @@ package org.dromara.web.service.impl; import cn.dev33.satoken.stp.SaLoginModel; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.lang.Validator; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; @@ -12,12 +13,12 @@ import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.domain.model.LoginUser; import org.dromara.common.core.enums.LoginType; import org.dromara.common.core.enums.UserStatus; +import org.dromara.common.core.exception.user.AuthException; import org.dromara.common.core.exception.user.CaptchaExpireException; import org.dromara.common.core.exception.user.UserException; import org.dromara.common.core.utils.MessageUtils; +import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.StringUtils; -import org.dromara.common.core.utils.ValidatorUtils; -import org.dromara.common.core.validate.auth.EmailGroup; import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.tenant.helper.TenantHelper; @@ -44,15 +45,26 @@ public class EmailAuthStrategy implements IAuthStrategy { private final SysUserMapper userMapper; @Override - public void validate(LoginBody loginBody) { - ValidatorUtils.validate(loginBody, EmailGroup.class); + public void validate() { + String email = ServletUtils.getParamFromBody("email"); + String emailCode = ServletUtils.getParamFromBody("emailCode"); + if (StringUtils.isBlank(email)) { + throw new AuthException("user.email.not.blank"); + } + if (StringUtils.isBlank(emailCode)) { + throw new AuthException("email.code.not.blank"); + } + // 校验邮箱是否合法 + if (!Validator.isEmail(email, true)) { + throw new AuthException("user.email.not.valid"); + } } @Override public LoginVo login(String clientId, LoginBody loginBody, SysClient client) { String tenantId = loginBody.getTenantId(); - String email = loginBody.getEmail(); - String emailCode = loginBody.getEmailCode(); + String email = ServletUtils.getParamFromBody("email"); + String emailCode = ServletUtils.getParamFromBody("emailCode"); // 通过邮箱查找用户 SysUserVo user = loadUserByEmail(tenantId, email); diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java index 46bd5661f..d31f6d173 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java @@ -3,23 +3,26 @@ package org.dromara.web.service.impl; import cn.dev33.satoken.secure.BCrypt; import cn.dev33.satoken.stp.SaLoginModel; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.lang.Validator; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.constant.Constants; import org.dromara.common.core.constant.GlobalConstants; +import org.dromara.common.core.constant.UserConstants; import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.domain.model.LoginUser; import org.dromara.common.core.enums.LoginType; import org.dromara.common.core.enums.UserStatus; +import org.dromara.common.core.exception.user.AuthException; import org.dromara.common.core.exception.user.CaptchaException; import org.dromara.common.core.exception.user.CaptchaExpireException; import org.dromara.common.core.exception.user.UserException; import org.dromara.common.core.utils.MessageUtils; +import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.ValidatorUtils; -import org.dromara.common.core.validate.auth.PasswordGroup; import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.tenant.helper.TenantHelper; @@ -48,8 +51,8 @@ public class PasswordAuthStrategy implements IAuthStrategy { private final SysUserMapper userMapper; @Override - public void validate(LoginBody loginBody) { - ValidatorUtils.validate(loginBody, PasswordGroup.class); + public void validate() { + ValidatorUtils.validate(ServletUtils.getParamBody()); } @Override diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java index 0ddb75350..4b90f9caa 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java @@ -12,12 +12,12 @@ import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.domain.model.LoginUser; import org.dromara.common.core.enums.LoginType; import org.dromara.common.core.enums.UserStatus; +import org.dromara.common.core.exception.user.AuthException; import org.dromara.common.core.exception.user.CaptchaExpireException; import org.dromara.common.core.exception.user.UserException; import org.dromara.common.core.utils.MessageUtils; +import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.StringUtils; -import org.dromara.common.core.utils.ValidatorUtils; -import org.dromara.common.core.validate.auth.SmsGroup; import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.tenant.helper.TenantHelper; @@ -44,15 +44,22 @@ public class SmsAuthStrategy implements IAuthStrategy { private final SysUserMapper userMapper; @Override - public void validate(LoginBody loginBody) { - ValidatorUtils.validate(loginBody, SmsGroup.class); + public void validate() { + String phonenumber = ServletUtils.getParamFromBody("phonenumber"); + String smsCode = ServletUtils.getParamFromBody("smsCode"); + if (StringUtils.isBlank(phonenumber)) { + throw new AuthException("user.phonenumber.not.blank"); + } + if (StringUtils.isBlank(smsCode)) { + throw new AuthException("sms.code.not.blank"); + } } @Override public LoginVo login(String clientId, LoginBody loginBody, SysClient client) { String tenantId = loginBody.getTenantId(); - String phonenumber = loginBody.getPhonenumber(); - String smsCode = loginBody.getSmsCode(); + String phonenumber = ServletUtils.getParamFromBody("phonenumber"); + String smsCode = ServletUtils.getParamFromBody("smsCode"); // 通过手机号查找用户 SysUserVo user = loadUserByPhonenumber(tenantId, phonenumber); diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java index 2b055df06..2c7842b37 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java @@ -17,10 +17,11 @@ import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.domain.model.LoginUser; import org.dromara.common.core.enums.UserStatus; import org.dromara.common.core.exception.ServiceException; +import org.dromara.common.core.exception.user.AuthException; import org.dromara.common.core.exception.user.UserException; import org.dromara.common.core.utils.MessageUtils; -import org.dromara.common.core.utils.ValidatorUtils; -import org.dromara.common.core.validate.auth.SocialGroup; +import org.dromara.common.core.utils.ServletUtils; +import org.dromara.common.core.utils.StringUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.social.config.properties.SocialProperties; import org.dromara.common.social.utils.SocialUtils; @@ -53,8 +54,19 @@ public class SocialAuthStrategy implements IAuthStrategy { @Override - public void validate(LoginBody loginBody) { - ValidatorUtils.validate(loginBody, SocialGroup.class); + public void validate() { + String source = ServletUtils.getParamFromBody("source"); + String socialCode = ServletUtils.getParamFromBody("socialCode"); + String socialState = ServletUtils.getParamFromBody("socialState"); + if (StringUtils.isBlank(source)) { + throw new AuthException("social.source.not.blank"); + } + if (StringUtils.isBlank(socialCode)) { + throw new AuthException("social.code.not.blank"); + } + if (StringUtils.isBlank(socialState)) { + throw new AuthException("social.state.not.blank"); + } } /** diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java index 5016e5bc4..926eaf898 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java @@ -9,9 +9,10 @@ import org.dromara.common.core.constant.Constants; import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.domain.model.XcxLoginUser; import org.dromara.common.core.enums.UserStatus; +import org.dromara.common.core.exception.user.AuthException; import org.dromara.common.core.utils.MessageUtils; -import org.dromara.common.core.utils.ValidatorUtils; -import org.dromara.common.core.validate.auth.WechatGroup; +import org.dromara.common.core.utils.ServletUtils; +import org.dromara.common.core.utils.StringUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.system.domain.SysClient; import org.dromara.system.domain.vo.SysUserVo; @@ -33,14 +34,17 @@ public class XcxAuthStrategy implements IAuthStrategy { private final SysLoginService loginService; @Override - public void validate(LoginBody loginBody) { - ValidatorUtils.validate(loginBody, WechatGroup.class); + public void validate() { + String xcxCode = ServletUtils.getParamFromBody("xcxCode"); + if (StringUtils.isBlank(xcxCode)) { + throw new AuthException("xcx.code.not.blank"); + } } @Override public LoginVo login(String clientId, LoginBody loginBody, SysClient client) { // xcxCode 为 小程序调用 wx.login 授权后获取 - String xcxCode = loginBody.getXcxCode(); + String xcxCode = ServletUtils.getParamFromBody("xcxCode"); // todo 以下自行实现 // 校验 appid + appsrcret + xcxCode 调用登录凭证校验接口 获取 session_key 与 openid String openid = ""; diff --git a/ruoyi-admin/src/main/resources/i18n/messages.properties b/ruoyi-admin/src/main/resources/i18n/messages.properties index c8635612a..f3dd4a83a 100644 --- a/ruoyi-admin/src/main/resources/i18n/messages.properties +++ b/ruoyi-admin/src/main/resources/i18n/messages.properties @@ -51,6 +51,9 @@ email.code.not.blank=邮箱验证码不能为空 email.code.retry.limit.count=邮箱验证码输入错误{0}次 email.code.retry.limit.exceed=邮箱验证码输入错误{0}次,帐户锁定{1}分钟 xcx.code.not.blank=小程序code不能为空 +social.source.not.blank=第三方登录平台不能为空 +social.code.not.blank=第三方登录code不能为空 +social.state.not.blank=第三方登录socialState不能为空 ##租户 tenant.number.not.blank=租户编号不能为空 tenant.not.exists=对不起, 您的租户不存在,请联系管理员 diff --git a/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties b/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties index 355da8432..0a84fe4a3 100644 --- a/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties +++ b/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties @@ -51,6 +51,9 @@ email.code.not.blank=Email code cannot be blank email.code.retry.limit.count=Email code input error {0} times email.code.retry.limit.exceed=Email code input error {0} times, account locked for {1} minutes xcx.code.not.blank=Mini program code cannot be blank +social.source.not.blank=social source cannot be blank +social.code.not.blank=social code cannot be blank +social.state.not.blank=social state cannot be blank ##租户 tenant.number.not.blank=Tenant number cannot be blank tenant.not.exists=Sorry, your tenant does not exist. Please contact the administrator diff --git a/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties b/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties index c8635612a..f3dd4a83a 100644 --- a/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties +++ b/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties @@ -51,6 +51,9 @@ email.code.not.blank=邮箱验证码不能为空 email.code.retry.limit.count=邮箱验证码输入错误{0}次 email.code.retry.limit.exceed=邮箱验证码输入错误{0}次,帐户锁定{1}分钟 xcx.code.not.blank=小程序code不能为空 +social.source.not.blank=第三方登录平台不能为空 +social.code.not.blank=第三方登录code不能为空 +social.state.not.blank=第三方登录socialState不能为空 ##租户 tenant.number.not.blank=租户编号不能为空 tenant.not.exists=对不起, 您的租户不存在,请联系管理员 diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginBody.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginBody.java index 71e499178..68ab5bda7 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginBody.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginBody.java @@ -1,10 +1,8 @@ package org.dromara.common.core.domain.model; -import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; import lombok.Data; import org.dromara.common.core.constant.UserConstants; -import org.dromara.common.core.validate.auth.*; import org.hibernate.validator.constraints.Length; /** @@ -22,16 +20,6 @@ public class LoginBody { @NotBlank(message = "{auth.clientid.not.blank}") private String clientId; - /** - * 客户端key - */ - private String clientKey; - - /** - * 客户端秘钥 - */ - private String clientSecret; - /** * 授权类型 */ @@ -46,15 +34,15 @@ public class LoginBody { /** * 用户名 */ - @NotBlank(message = "{user.username.not.blank}", groups = {PasswordGroup.class}) - @Length(min = UserConstants.USERNAME_MIN_LENGTH, max = UserConstants.USERNAME_MAX_LENGTH, message = "{user.username.length.valid}", groups = {PasswordGroup.class}) + @NotBlank(message = "{user.username.not.blank}") + @Length(min = UserConstants.USERNAME_MIN_LENGTH, max = UserConstants.USERNAME_MAX_LENGTH, message = "{user.username.length.valid}") private String username; /** * 用户密码 */ - @NotBlank(message = "{user.password.not.blank}", groups = {PasswordGroup.class}) - @Length(min = UserConstants.PASSWORD_MIN_LENGTH, max = UserConstants.PASSWORD_MAX_LENGTH, message = "{user.password.length.valid}", groups = {PasswordGroup.class}) + @NotBlank(message = "{user.password.not.blank}") + @Length(min = UserConstants.PASSWORD_MIN_LENGTH, max = UserConstants.PASSWORD_MAX_LENGTH, message = "{user.password.length.valid}") private String password; /** @@ -67,52 +55,4 @@ public class LoginBody { */ private String uuid; - /** - * 手机号 - */ - @NotBlank(message = "{user.phonenumber.not.blank}", groups = {SmsGroup.class}) - private String phonenumber; - - /** - * 短信code - */ - @NotBlank(message = "{sms.code.not.blank}", groups = {SmsGroup.class}) - private String smsCode; - - /** - * 邮箱 - */ - @NotBlank(message = "{user.email.not.blank}", groups = {EmailGroup.class}) - @Email(message = "{user.email.not.valid}") - private String email; - - /** - * 邮箱code - */ - @NotBlank(message = "{email.code.not.blank}", groups = {EmailGroup.class}) - private String emailCode; - - /** - * 小程序code - */ - @NotBlank(message = "{xcx.code.not.blank}", groups = {WechatGroup.class}) - private String xcxCode; - - /** - * 第三方登录平台 - */ - @NotBlank(message = "{social.source.not.blank}" , groups = {SocialGroup.class}) - private String source; - - /** - * 第三方登录code - */ - @NotBlank(message = "{social.code.not.blank}" , groups = {SocialGroup.class}) - private String socialCode; - - /** - * 第三方登录socialState - */ - @NotBlank(message = "{social.state.not.blank}" , groups = {SocialGroup.class}) - private String socialState; } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/exception/user/AuthException.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/exception/user/AuthException.java new file mode 100644 index 000000000..185611b90 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/exception/user/AuthException.java @@ -0,0 +1,21 @@ +package org.dromara.common.core.exception.user; + +import org.dromara.common.core.exception.base.BaseException; + +import java.io.Serial; + +/** + * 认证异常类 + * + * @author Michelle.Chung + */ +public class AuthException extends BaseException { + + @Serial + private static final long serialVersionUID = 1L; + + public AuthException(String code, Object... args) { + super("auth", code, args, null); + } + +} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ServletUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ServletUtils.java index a1316eb85..ded061cb7 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ServletUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ServletUtils.java @@ -3,6 +3,8 @@ package org.dromara.common.core.utils; import cn.hutool.core.convert.Convert; import cn.hutool.extra.servlet.JakartaServletUtil; import cn.hutool.http.HttpStatus; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -19,10 +21,7 @@ import java.io.IOException; import java.net.URLDecoder; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * 客户端工具类 @@ -99,6 +98,39 @@ public class ServletUtils extends JakartaServletUtil { return params; } + /** + * 获取请求体 + * + * @return json + */ + public static JSONObject getParamBody() { + String body = ServletUtils.getBody(Objects.requireNonNull(ServletUtils.getRequest())); + return StringUtils.isBlank(body) ? new JSONObject() : new JSONObject(body); + } + + /** + * 获取请求体 json 参数值 + * + * @param key json key + * @return 参数值 + */ + public static String getParamFromBody(String key) { + return getParamFromBody(key, String.class); + } + + /** + * 获取请求体 json 参数值 + * + * @param key json key + * @param clazz 参数类 + * @param 参数类型 + * @return 参数值 + */ + public static T getParamFromBody(String key, Class clazz) { + JSONObject body = getParamBody(); + return !JSONUtil.isNull(body) ? body.get(key, clazz) : null; + } + /** * 获取request */ diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/EmailGroup.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/EmailGroup.java deleted file mode 100644 index 345a8e7cb..000000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/EmailGroup.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dromara.common.core.validate.auth; - -/** - * @author Michelle.Chung - */ -public interface EmailGroup { -} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/PasswordGroup.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/PasswordGroup.java deleted file mode 100644 index b2c06b80d..000000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/PasswordGroup.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dromara.common.core.validate.auth; - -/** - * @author Michelle.Chung - */ -public interface PasswordGroup { -} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SmsGroup.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SmsGroup.java deleted file mode 100644 index e6fc65769..000000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SmsGroup.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dromara.common.core.validate.auth; - -/** - * @author Michelle.Chung - */ -public interface SmsGroup { -} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SocialGroup.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SocialGroup.java deleted file mode 100644 index 2b19ffe30..000000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SocialGroup.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.dromara.common.core.validate.auth; - -public interface SocialGroup { -} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/WechatGroup.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/WechatGroup.java deleted file mode 100644 index 1955de217..000000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/WechatGroup.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dromara.common.core.validate.auth; - -/** - * @author Michelle.Chung - */ -public interface WechatGroup { -} diff --git a/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java b/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java index 0c636c255..d1e33aca6 100644 --- a/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java +++ b/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java @@ -8,6 +8,7 @@ import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.request.*; import org.dromara.common.core.domain.model.LoginBody; +import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.social.config.properties.SocialLoginConfigProperties; import org.dromara.common.social.config.properties.SocialProperties; @@ -24,10 +25,13 @@ public class SocialUtils { @SuppressWarnings("unchecked") public static AuthResponse loginAuth(LoginBody loginBody, SocialProperties socialProperties) throws AuthException { - AuthRequest authRequest = getAuthRequest(loginBody.getSource(), socialProperties); + String source = ServletUtils.getParamFromBody("source"); + String socialCode = ServletUtils.getParamFromBody("socialCode"); + String socialState = ServletUtils.getParamFromBody("socialState"); + AuthRequest authRequest = getAuthRequest(source, socialProperties); AuthCallback callback = new AuthCallback(); - callback.setCode(loginBody.getSocialCode()); - callback.setState(loginBody.getSocialState()); + callback.setCode(socialCode); + callback.setState(socialState); return authRequest.login(callback); }