Commit 7227664f7796843589906354501a530fff07a20d
1 parent
878445a2
进一步重构社交登陆的实现
Showing
21 changed files
with
155 additions
and
134 deletions
yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/config/YudaoSocialAutoConfiguration.java
| 1 | 1 | package cn.iocoder.yudao.framework.social.config; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.ReflectUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.social.core.YudaoAuthRequestFactory; |
| 5 | +import com.xkcoding.http.HttpUtil; | |
| 6 | +import com.xkcoding.http.support.hutool.HutoolImpl; | |
| 4 | 7 | import com.xkcoding.justauth.autoconfigure.JustAuthProperties; |
| 5 | 8 | import lombok.extern.slf4j.Slf4j; |
| 6 | 9 | import me.zhyd.oauth.cache.AuthStateCache; |
| ... | ... | @@ -23,6 +26,9 @@ public class YudaoSocialAutoConfiguration { |
| 23 | 26 | @Bean |
| 24 | 27 | @ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true) |
| 25 | 28 | public YudaoAuthRequestFactory yudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { |
| 29 | + // 需要修改 HttpUtil 使用的实现,避免类报错 | |
| 30 | + HttpUtil.setHttp(new HutoolImpl()); | |
| 31 | + // 创建 YudaoAuthRequestFactory | |
| 26 | 32 | return new YudaoAuthRequestFactory(properties, authStateCache); |
| 27 | 33 | } |
| 28 | 34 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
| ... | ... | @@ -36,7 +36,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti |
| 36 | 36 | |
| 37 | 37 | @Api(tags = "管理后台 - 认证") |
| 38 | 38 | @RestController |
| 39 | -@RequestMapping("/system") // 暂时不跟 /auth 结尾 | |
| 39 | +@RequestMapping("/system/auth") // 暂时不跟 /auth 结尾 | |
| 40 | 40 | @Validated |
| 41 | 41 | @Slf4j |
| 42 | 42 | public class AuthController { |
| ... | ... | @@ -80,7 +80,7 @@ public class AuthController { |
| 80 | 80 | return success(AuthConvert.INSTANCE.convert(user, roleList, menuList)); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - @GetMapping("list-menus") | |
| 83 | + @GetMapping("/list-menus") | |
| 84 | 84 | @ApiOperation("获得登录用户的菜单列表") |
| 85 | 85 | public CommonResult<List<AuthMenuRespVO>> getMenus() { |
| 86 | 86 | // 获得用户拥有的菜单列表 |
| ... | ... | @@ -105,36 +105,22 @@ public class AuthController { |
| 105 | 105 | return CommonResult.success(socialUserService.getAuthorizeUrl(type, redirectUri)); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - @PostMapping("/social-login") | |
| 109 | - @ApiOperation("社交登录,使用 code 授权码") | |
| 108 | + @PostMapping("/social-quick-login") | |
| 109 | + @ApiOperation("社交快捷登录,使用 code 授权码") | |
| 110 | 110 | @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 |
| 111 | - public CommonResult<AuthLoginRespVO> socialLogin(@RequestBody @Valid AuthSocialLoginReqVO reqVO) { | |
| 111 | + public CommonResult<AuthLoginRespVO> socialQuickLogin(@RequestBody @Valid AuthSocialQuickLoginReqVO reqVO) { | |
| 112 | 112 | String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent()); |
| 113 | 113 | // 返回结果 |
| 114 | 114 | return success(AuthLoginRespVO.builder().token(token).build()); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - @PostMapping("/social-login2") | |
| 118 | - @ApiOperation("社交登录,使用 code 授权码 + 账号密码") | |
| 117 | + @PostMapping("/social-bind-login") | |
| 118 | + @ApiOperation("社交绑定登录,使用 code 授权码 + 账号密码") | |
| 119 | 119 | @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 |
| 120 | - public CommonResult<AuthLoginRespVO> socialLogin2(@RequestBody @Valid AuthSocialLogin2ReqVO reqVO) { | |
| 121 | - String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent()); | |
| 120 | + public CommonResult<AuthLoginRespVO> socialBindLogin(@RequestBody @Valid AuthSocialBindLoginReqVO reqVO) { | |
| 121 | + String token = authService.socialBindLogin(reqVO, getClientIP(), getUserAgent()); | |
| 122 | 122 | // 返回结果 |
| 123 | 123 | return success(AuthLoginRespVO.builder().token(token).build()); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - @PostMapping("/social-bind") | |
| 127 | - @ApiOperation("社交绑定,使用 code 授权码") | |
| 128 | - public CommonResult<Boolean> socialBind(@RequestBody @Valid AuthSocialBindReqVO reqVO) { | |
| 129 | - authService.socialBind(getLoginUserId(), reqVO); | |
| 130 | - return CommonResult.success(true); | |
| 131 | - } | |
| 132 | - | |
| 133 | - @DeleteMapping("/social-unbind") | |
| 134 | - @ApiOperation("取消社交绑定") | |
| 135 | - public CommonResult<Boolean> socialUnbind(@RequestBody AuthSocialUnbindReqVO reqVO) { | |
| 136 | - socialUserService.unbindSocialUser(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getUnionId()); | |
| 137 | - return CommonResult.success(true); | |
| 138 | - } | |
| 139 | - | |
| 140 | 126 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialLogin2ReqVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialBindLoginReqVO.java
| ... | ... | @@ -14,12 +14,12 @@ import javax.validation.constraints.NotEmpty; |
| 14 | 14 | import javax.validation.constraints.NotNull; |
| 15 | 15 | import javax.validation.constraints.Pattern; |
| 16 | 16 | |
| 17 | -@ApiModel("管理后台 - 社交登录 Request VO,使用 code 授权码 + 账号密码") | |
| 17 | +@ApiModel("管理后台 - 社交绑定登录 Request VO,使用 code 授权码 + 账号密码") | |
| 18 | 18 | @Data |
| 19 | 19 | @NoArgsConstructor |
| 20 | 20 | @AllArgsConstructor |
| 21 | 21 | @Builder |
| 22 | -public class AuthSocialLogin2ReqVO { | |
| 22 | +public class AuthSocialBindLoginReqVO { | |
| 23 | 23 | |
| 24 | 24 | @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 UserSocialTypeEnum 枚举值") |
| 25 | 25 | @InEnum(SocialTypeEnum.class) | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialLoginReqVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialQuickLoginReqVO.java
| ... | ... | @@ -12,12 +12,12 @@ import lombok.NoArgsConstructor; |
| 12 | 12 | import javax.validation.constraints.NotEmpty; |
| 13 | 13 | import javax.validation.constraints.NotNull; |
| 14 | 14 | |
| 15 | -@ApiModel("管理后台 - 社交登录 Request VO,使用 code 授权码") | |
| 15 | +@ApiModel("管理后台 - 社交快捷登录 Request VO,使用 code 授权码") | |
| 16 | 16 | @Data |
| 17 | 17 | @NoArgsConstructor |
| 18 | 18 | @AllArgsConstructor |
| 19 | 19 | @Builder |
| 20 | -public class AuthSocialLoginReqVO { | |
| 20 | +public class AuthSocialQuickLoginReqVO { | |
| 21 | 21 | |
| 22 | 22 | @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 UserSocialTypeEnum 枚举值") |
| 23 | 23 | @InEnum(SocialTypeEnum.class) | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.system.controller.admin.socail; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; | |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialUnbindReqVO; | |
| 7 | +import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; | |
| 8 | +import cn.iocoder.yudao.module.system.service.social.SocialUserService; | |
| 9 | +import io.swagger.annotations.Api; | |
| 10 | +import io.swagger.annotations.ApiOperation; | |
| 11 | +import org.springframework.validation.annotation.Validated; | |
| 12 | +import org.springframework.web.bind.annotation.*; | |
| 13 | + | |
| 14 | +import javax.annotation.Resource; | |
| 15 | +import javax.validation.Valid; | |
| 16 | + | |
| 17 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 18 | + | |
| 19 | +@Api(tags = "管理后台 - 社交用户") | |
| 20 | +@RestController | |
| 21 | +@RequestMapping("/system/social-user") | |
| 22 | +@Validated | |
| 23 | +public class SocialUserController { | |
| 24 | + | |
| 25 | + @Resource | |
| 26 | + private SocialUserService socialUserService; | |
| 27 | + | |
| 28 | + @PostMapping("/bind") | |
| 29 | + @ApiOperation("社交绑定,使用 code 授权码") | |
| 30 | + public CommonResult<Boolean> socialBind(@RequestBody @Valid AuthSocialBindReqVO reqVO) { | |
| 31 | + socialUserService.bindSocialUser(SocialUserConvert.INSTANCE.convert(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO)); | |
| 32 | + return CommonResult.success(true); | |
| 33 | + } | |
| 34 | + | |
| 35 | + @DeleteMapping("/unbind") | |
| 36 | + @ApiOperation("取消社交绑定") | |
| 37 | + public CommonResult<Boolean> socialUnbind(@RequestBody AuthSocialUnbindReqVO reqVO) { | |
| 38 | + socialUserService.unbindSocialUser(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getUnionId()); | |
| 39 | + return CommonResult.success(true); | |
| 40 | + } | |
| 41 | + | |
| 42 | +} | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/profile/UserProfileRespVO.java
| ... | ... | @@ -96,8 +96,8 @@ public class UserProfileRespVO extends UserBaseVO { |
| 96 | 96 | @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SocialTypeEnum 枚举类") |
| 97 | 97 | private Integer type; |
| 98 | 98 | |
| 99 | - @ApiModelProperty(value = "社交的全局编号", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") | |
| 100 | - private String unionId; | |
| 99 | + @ApiModelProperty(value = "社交用户的 openid", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") | |
| 100 | + private String openid; | |
| 101 | 101 | |
| 102 | 102 | } |
| 103 | 103 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/AuthConvert.java
| ... | ... | @@ -72,9 +72,8 @@ public interface AuthConvert { |
| 72 | 72 | return CollectionUtils.filterList(treeNodeMap.values(), node -> MenuIdEnum.ROOT.getId().equals(node.getParentId())); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialBindReqVO reqVO); | |
| 76 | - SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLogin2ReqVO reqVO); | |
| 77 | - SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLoginReqVO reqVO); | |
| 78 | - SocialUserUnbindReqDTO convert(Long userId, Integer userType, AuthSocialUnbindReqVO reqVO); | |
| 75 | + SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialBindLoginReqVO reqVO); | |
| 76 | + | |
| 77 | + SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialQuickLoginReqVO reqVO); | |
| 79 | 78 | |
| 80 | 79 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.system.convert.social; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; | |
| 4 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; | |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialUnbindReqVO; | |
| 7 | +import org.mapstruct.Mapper; | |
| 8 | +import org.mapstruct.factory.Mappers; | |
| 9 | + | |
| 10 | +@Mapper | |
| 11 | +public interface SocialUserConvert { | |
| 12 | + | |
| 13 | + SocialUserConvert INSTANCE = Mappers.getMapper(SocialUserConvert.class); | |
| 14 | + | |
| 15 | + SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialBindReqVO reqVO); | |
| 16 | + | |
| 17 | + SocialUserUnbindReqDTO convert(Long userId, Integer userType, AuthSocialUnbindReqVO reqVO); | |
| 18 | + | |
| 19 | +} | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/social/SocialUserBindDO.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.dal.dataobject.social; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | -import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | |
| 6 | 5 | import com.baomidou.mybatisplus.annotation.TableName; |
| 7 | 6 | import lombok.*; |
| 8 | 7 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java
| ... | ... | @@ -18,14 +18,18 @@ public class SecurityConfiguration { |
| 18 | 18 | |
| 19 | 19 | @Override |
| 20 | 20 | public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) { |
| 21 | - // 登录的接口,可匿名访问 | |
| 22 | - registry.antMatchers(buildAdminApi("/system/login")).anonymous(); | |
| 21 | + // 登录的接口 | |
| 22 | + registry.antMatchers(buildAdminApi("/system/auth/login")).permitAll(); | |
| 23 | + // 社交登陆的接口 | |
| 24 | + registry.antMatchers(buildAdminApi("/system/auth/social-auth-redirect")).permitAll(); | |
| 25 | + registry.antMatchers(buildAdminApi("/system/auth/social-quick-login")).permitAll(); | |
| 26 | + registry.antMatchers(buildAdminApi("/system/auth/social-bind-login")).permitAll(); | |
| 23 | 27 | // 验证码的接口 |
| 24 | - registry.antMatchers(buildAdminApi("/system/captcha/**")).anonymous(); | |
| 28 | + registry.antMatchers(buildAdminApi("/system/captcha/**")).permitAll(); | |
| 25 | 29 | // 获得租户编号的接口 |
| 26 | - registry.antMatchers(buildAdminApi("/system/tenant/get-id-by-name")).anonymous(); | |
| 30 | + registry.antMatchers(buildAdminApi("/system/tenant/get-id-by-name")).permitAll(); | |
| 27 | 31 | // 短信回调 API |
| 28 | - registry.antMatchers(buildAdminApi("/system/sms/callback/**")).anonymous(); | |
| 32 | + registry.antMatchers(buildAdminApi("/system/sms/callback/**")).permitAll(); | |
| 29 | 33 | } |
| 30 | 34 | |
| 31 | 35 | }; | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java
| ... | ... | @@ -25,31 +25,23 @@ public interface AdminAuthService extends SecurityAuthFrameworkService { |
| 25 | 25 | String login(@Valid AuthLoginReqVO reqVO, String userIp, String userAgent); |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * 社交登录,使用 code 授权码 | |
| 28 | + * 社交快捷登录,使用 code 授权码 | |
| 29 | 29 | * |
| 30 | 30 | * @param reqVO 登录信息 |
| 31 | 31 | * @param userIp 用户 IP |
| 32 | 32 | * @param userAgent 用户 UA |
| 33 | 33 | * @return 身份令牌,使用 JWT 方式 |
| 34 | 34 | */ |
| 35 | - String socialLogin(@Valid AuthSocialLoginReqVO reqVO, String userIp, String userAgent); | |
| 35 | + String socialLogin(@Valid AuthSocialQuickLoginReqVO reqVO, String userIp, String userAgent); | |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * 社交登录,使用 code 授权码 + 账号密码 | |
| 38 | + * 社交绑定登录,使用 code 授权码 + 账号密码 | |
| 39 | 39 | * |
| 40 | 40 | * @param reqVO 登录信息 |
| 41 | 41 | * @param userIp 用户 IP |
| 42 | 42 | * @param userAgent 用户 UA |
| 43 | 43 | * @return 身份令牌,使用 JWT 方式 |
| 44 | 44 | */ |
| 45 | - String socialLogin2(@Valid AuthSocialLogin2ReqVO reqVO, String userIp, String userAgent); | |
| 46 | - | |
| 47 | - /** | |
| 48 | - * 社交绑定,使用 code 授权码 | |
| 49 | - * | |
| 50 | - * @param userId 用户编号 | |
| 51 | - * @param reqVO 绑定信息 | |
| 52 | - */ | |
| 53 | - void socialBind(Long userId, @Valid AuthSocialBindReqVO reqVO); | |
| 45 | + String socialBindLogin(@Valid AuthSocialBindLoginReqVO reqVO, String userIp, String userAgent); | |
| 54 | 46 | |
| 55 | 47 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
| ... | ... | @@ -9,9 +9,9 @@ import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 9 | 9 | import cn.iocoder.yudao.framework.security.core.authentication.MultiUsernamePasswordAuthenticationToken; |
| 10 | 10 | import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; |
| 11 | 11 | import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthLoginReqVO; |
| 12 | +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindLoginReqVO; | |
| 12 | 13 | import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; |
| 13 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialLogin2ReqVO; | |
| 14 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialLoginReqVO; | |
| 14 | +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialQuickLoginReqVO; | |
| 15 | 15 | import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; |
| 16 | 16 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 17 | 17 | import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; |
| ... | ... | @@ -22,7 +22,6 @@ import cn.iocoder.yudao.module.system.service.permission.PermissionService; |
| 22 | 22 | import cn.iocoder.yudao.module.system.service.social.SocialUserService; |
| 23 | 23 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 24 | 24 | import lombok.extern.slf4j.Slf4j; |
| 25 | -import me.zhyd.oauth.model.AuthUser; | |
| 26 | 25 | import org.springframework.beans.factory.annotation.Autowired; |
| 27 | 26 | import org.springframework.context.annotation.Lazy; |
| 28 | 27 | import org.springframework.security.authentication.AuthenticationManager; |
| ... | ... | @@ -82,7 +81,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { |
| 82 | 81 | throw new UsernameNotFoundException(username); |
| 83 | 82 | } |
| 84 | 83 | // 创建 LoginUser 对象 |
| 85 | - return this.buildLoginUser(user); | |
| 84 | + return buildLoginUser(user); | |
| 86 | 85 | } |
| 87 | 86 | |
| 88 | 87 | @Override |
| ... | ... | @@ -92,19 +91,19 @@ public class AdminAuthServiceImpl implements AdminAuthService { |
| 92 | 91 | if (user == null) { |
| 93 | 92 | throw new UsernameNotFoundException(String.valueOf(userId)); |
| 94 | 93 | } |
| 95 | - this.createLoginLog(user.getUsername(), LoginLogTypeEnum.LOGIN_MOCK, LoginResultEnum.SUCCESS); | |
| 94 | + createLoginLog(user.getUsername(), LoginLogTypeEnum.LOGIN_MOCK, LoginResultEnum.SUCCESS); | |
| 96 | 95 | |
| 97 | 96 | // 创建 LoginUser 对象 |
| 98 | - return this.buildLoginUser(user); | |
| 97 | + return buildLoginUser(user); | |
| 99 | 98 | } |
| 100 | 99 | |
| 101 | 100 | @Override |
| 102 | 101 | public String login(AuthLoginReqVO reqVO, String userIp, String userAgent) { |
| 103 | 102 | // 判断验证码是否正确 |
| 104 | - this.verifyCaptcha(reqVO); | |
| 103 | + verifyCaptcha(reqVO); | |
| 105 | 104 | |
| 106 | 105 | // 使用账号密码,进行登录 |
| 107 | - LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); | |
| 106 | + LoginUser loginUser = login0(reqVO.getUsername(), reqVO.getPassword()); | |
| 108 | 107 | |
| 109 | 108 | // 缓存登陆用户到 Redis 中,返回 sessionId 编号 |
| 110 | 109 | return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_USERNAME, userIp, userAgent); |
| ... | ... | @@ -192,7 +191,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { |
| 192 | 191 | } |
| 193 | 192 | |
| 194 | 193 | @Override |
| 195 | - public String socialLogin(AuthSocialLoginReqVO reqVO, String userIp, String userAgent) { | |
| 194 | + public String socialLogin(AuthSocialQuickLoginReqVO reqVO, String userIp, String userAgent) { | |
| 196 | 195 | // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 |
| 197 | 196 | Long userId = socialUserService.getBindUserId(UserTypeEnum.ADMIN.getValue(), reqVO.getType(), |
| 198 | 197 | reqVO.getCode(), reqVO.getState()); |
| ... | ... | @@ -207,24 +206,18 @@ public class AdminAuthServiceImpl implements AdminAuthService { |
| 207 | 206 | } |
| 208 | 207 | |
| 209 | 208 | // 创建 LoginUser 对象 |
| 210 | - LoginUser loginUser = this.buildLoginUser(user); | |
| 211 | - | |
| 212 | - // 绑定社交用户(更新) | |
| 213 | - socialUserService.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO)); | |
| 209 | + LoginUser loginUser = buildLoginUser(user); | |
| 214 | 210 | |
| 215 | 211 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 216 | 212 | return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_SOCIAL, userIp, userAgent); |
| 217 | 213 | } |
| 218 | 214 | |
| 219 | 215 | @Override |
| 220 | - public String socialLogin2(AuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { | |
| 221 | - // 使用 code 授权码,进行登录 | |
| 222 | - socialUserService.authSocialUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); | |
| 223 | - | |
| 216 | + public String socialBindLogin(AuthSocialBindLoginReqVO reqVO, String userIp, String userAgent) { | |
| 224 | 217 | // 使用账号密码,进行登录。 |
| 225 | - LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); | |
| 218 | + LoginUser loginUser = login0(reqVO.getUsername(), reqVO.getPassword()); | |
| 226 | 219 | |
| 227 | - // 绑定社交用户(新增) | |
| 220 | + // 绑定社交用户 | |
| 228 | 221 | socialUserService.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO)); |
| 229 | 222 | |
| 230 | 223 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| ... | ... | @@ -239,12 +232,6 @@ public class AdminAuthServiceImpl implements AdminAuthService { |
| 239 | 232 | } |
| 240 | 233 | |
| 241 | 234 | @Override |
| 242 | - public void socialBind(Long userId, AuthSocialBindReqVO reqVO) { | |
| 243 | - // 绑定社交用户(新增) | |
| 244 | - socialUserService.bindSocialUser(AuthConvert.INSTANCE.convert(userId, getUserType().getValue(), reqVO)); | |
| 245 | - } | |
| 246 | - | |
| 247 | - @Override | |
| 248 | 235 | public void logout(String token) { |
| 249 | 236 | // 查询用户信息 |
| 250 | 237 | LoginUser loginUser = userSessionService.getLoginUser(token); | ... | ... |
yudao-server/src/main/resources/application-dev.yaml
| ... | ... | @@ -186,10 +186,6 @@ yudao: |
| 186 | 186 | justauth: |
| 187 | 187 | enabled: true |
| 188 | 188 | type: |
| 189 | - GITEE: # Gitee | |
| 190 | - client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1 | |
| 191 | - client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9 | |
| 192 | - ignore-check-redirect-uri: true | |
| 193 | 189 | DINGTALK: # 钉钉 |
| 194 | 190 | client-id: dingvrnreaje3yqvzhxg |
| 195 | 191 | client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI | ... | ... |
yudao-server/src/main/resources/application-local.yaml
| ... | ... | @@ -196,10 +196,6 @@ yudao: |
| 196 | 196 | justauth: |
| 197 | 197 | enabled: true |
| 198 | 198 | type: |
| 199 | - GITEE: # Gitee | |
| 200 | - client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1 | |
| 201 | - client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9 | |
| 202 | - ignore-check-redirect-uri: true | |
| 203 | 199 | DINGTALK: # 钉钉 |
| 204 | 200 | client-id: dingvrnreaje3yqvzhxg |
| 205 | 201 | client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI | ... | ... |
yudao-ui-admin/src/api/login.js
| ... | ... | @@ -9,7 +9,7 @@ export function login(username, password, code, uuid) { |
| 9 | 9 | uuid |
| 10 | 10 | } |
| 11 | 11 | return request({ |
| 12 | - url: '/system/login', | |
| 12 | + url: '/system/auth/login', | |
| 13 | 13 | method: 'post', |
| 14 | 14 | data: data |
| 15 | 15 | }) |
| ... | ... | @@ -18,7 +18,7 @@ export function login(username, password, code, uuid) { |
| 18 | 18 | // 获取用户详细信息 |
| 19 | 19 | export function getInfo() { |
| 20 | 20 | return request({ |
| 21 | - url: '/system/get-permission-info', | |
| 21 | + url: '/system/auth/get-permission-info', | |
| 22 | 22 | method: 'get' |
| 23 | 23 | }) |
| 24 | 24 | } |
| ... | ... | @@ -43,15 +43,15 @@ export function getCodeImg() { |
| 43 | 43 | // 社交授权的跳转 |
| 44 | 44 | export function socialAuthRedirect(type, redirectUri) { |
| 45 | 45 | return request({ |
| 46 | - url: '/system/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri, | |
| 46 | + url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri, | |
| 47 | 47 | method: 'get' |
| 48 | 48 | }) |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | -// 社交登录,使用 code 授权码 | |
| 52 | -export function socialLogin(type, code, state) { | |
| 51 | +// 社交快捷登录,使用 code 授权码 | |
| 52 | +export function socialQuickLogin(type, code, state) { | |
| 53 | 53 | return request({ |
| 54 | - url: '/system/social-login', | |
| 54 | + url: '/system/auth/social-quick-login', | |
| 55 | 55 | method: 'post', |
| 56 | 56 | data: { |
| 57 | 57 | type, |
| ... | ... | @@ -61,10 +61,10 @@ export function socialLogin(type, code, state) { |
| 61 | 61 | }) |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | -// 社交登录,使用 code 授权码 + + 账号密码 | |
| 65 | -export function socialLogin2(type, code, state, username, password) { | |
| 64 | +// 社交绑定登录,使用 code 授权码 + + 账号密码 | |
| 65 | +export function socialBindLogin(type, code, state, username, password) { | |
| 66 | 66 | return request({ |
| 67 | - url: '/system/social-login2', | |
| 67 | + url: '/system/auth/social-bind-login', | |
| 68 | 68 | method: 'post', |
| 69 | 69 | data: { |
| 70 | 70 | type, |
| ... | ... | @@ -75,28 +75,3 @@ export function socialLogin2(type, code, state, username, password) { |
| 75 | 75 | } |
| 76 | 76 | }) |
| 77 | 77 | } |
| 78 | - | |
| 79 | -// 社交绑定,使用 code 授权码 | |
| 80 | -export function socialBind(type, code, state) { | |
| 81 | - return request({ | |
| 82 | - url: '/system/social-bind', | |
| 83 | - method: 'post', | |
| 84 | - data: { | |
| 85 | - type, | |
| 86 | - code, | |
| 87 | - state, | |
| 88 | - } | |
| 89 | - }) | |
| 90 | -} | |
| 91 | - | |
| 92 | -// 取消社交绑定 | |
| 93 | -export function socialUnbind(type, unionId) { | |
| 94 | - return request({ | |
| 95 | - url: '/system/social-unbind', | |
| 96 | - method: 'delete', | |
| 97 | - data: { | |
| 98 | - type, | |
| 99 | - unionId | |
| 100 | - } | |
| 101 | - }) | |
| 102 | -} | ... | ... |
yudao-ui-admin/src/api/menu.js
yudao-ui-admin/src/api/system/socialUser.js
0 → 100644
| 1 | +import request from "@/utils/request"; | |
| 2 | + | |
| 3 | +// 社交绑定,使用 code 授权码 | |
| 4 | +export function socialBind(type, code, state) { | |
| 5 | + return request({ | |
| 6 | + url: '/system/social-user/bind', | |
| 7 | + method: 'post', | |
| 8 | + data: { | |
| 9 | + type, | |
| 10 | + code, | |
| 11 | + state, | |
| 12 | + } | |
| 13 | + }) | |
| 14 | +} | |
| 15 | + | |
| 16 | +// 取消社交绑定 | |
| 17 | +export function socialUnbind(type, unionId) { | |
| 18 | + return request({ | |
| 19 | + url: '/system/social-user/unbind', | |
| 20 | + method: 'delete', | |
| 21 | + data: { | |
| 22 | + type, | |
| 23 | + unionId | |
| 24 | + } | |
| 25 | + }) | |
| 26 | +} | ... | ... |
yudao-ui-admin/src/store/modules/user.js
| 1 | -import {login, logout, getInfo, socialLogin, socialLogin2} from '@/api/login' | |
| 1 | +import {login, logout, getInfo, socialQuickLogin, socialBindLogin} from '@/api/login' | |
| 2 | 2 | import { getToken, setToken, removeToken } from '@/utils/auth' |
| 3 | 3 | |
| 4 | 4 | const user = { |
| ... | ... | @@ -57,7 +57,7 @@ const user = { |
| 57 | 57 | const state = userInfo.state |
| 58 | 58 | const type = userInfo.type |
| 59 | 59 | return new Promise((resolve, reject) => { |
| 60 | - socialLogin(type, code, state).then(res => { | |
| 60 | + socialQuickLogin(type, code, state).then(res => { | |
| 61 | 61 | res = res.data; |
| 62 | 62 | setToken(res.token) |
| 63 | 63 | commit('SET_TOKEN', res.token) |
| ... | ... | @@ -76,7 +76,7 @@ const user = { |
| 76 | 76 | const username = userInfo.username.trim() |
| 77 | 77 | const password = userInfo.password |
| 78 | 78 | return new Promise((resolve, reject) => { |
| 79 | - socialLogin2(type, code, state, username, password).then(res => { | |
| 79 | + socialBindLogin(type, code, state, username, password).then(res => { | |
| 80 | 80 | res = res.data; |
| 81 | 81 | setToken(res.token) |
| 82 | 82 | commit('SET_TOKEN', res.token) | ... | ... |
yudao-ui-admin/src/utils/constants.js
| ... | ... | @@ -71,12 +71,6 @@ export const InfraApiErrorLogProcessStatusEnum = { |
| 71 | 71 | * 用户的社交平台的类型枚举 |
| 72 | 72 | */ |
| 73 | 73 | export const SystemUserSocialTypeEnum = { |
| 74 | - // GITEE: { | |
| 75 | - // title: "码云", | |
| 76 | - // type: 10, | |
| 77 | - // source: "gitee", | |
| 78 | - // img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.11/gitee.png", | |
| 79 | - // }, | |
| 80 | 74 | DINGTALK: { |
| 81 | 75 | title: "钉钉", |
| 82 | 76 | type: 20, | ... | ... |
yudao-ui-admin/src/views/login.vue
yudao-ui-admin/src/views/system/user/profile/userSocial.vue
| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | </el-table-column> |
| 8 | 8 | <el-table-column label="操作" align="left" > |
| 9 | 9 | <template slot-scope="scope"> |
| 10 | - <div v-if="scope.row.unionId"> | |
| 10 | + <div v-if="scope.row.openid"> | |
| 11 | 11 | 已绑定 |
| 12 | 12 | <el-button size="large" type="text" @click="unbind(scope.row)">(解绑)</el-button> |
| 13 | 13 | </div> |
| ... | ... | @@ -23,7 +23,8 @@ |
| 23 | 23 | <script> |
| 24 | 24 | |
| 25 | 25 | import {SystemUserSocialTypeEnum} from "@/utils/constants"; |
| 26 | -import {socialAuthRedirect, socialBind, socialUnbind} from "@/api/login"; | |
| 26 | +import {socialAuthRedirect} from "@/api/login"; | |
| 27 | +import {socialBind, socialUnbind} from "@/api/system/socialUser"; | |
| 27 | 28 | |
| 28 | 29 | export default { |
| 29 | 30 | props: { |
| ... | ... | @@ -50,7 +51,7 @@ export default { |
| 50 | 51 | if (this.user.socialUsers) { |
| 51 | 52 | for (const j in this.user.socialUsers) { |
| 52 | 53 | if (socialUser.type === this.user.socialUsers[j].type) { |
| 53 | - socialUser.unionId = this.user.socialUsers[j].unionId; | |
| 54 | + socialUser.openid = this.user.socialUsers[j].openid; | |
| 54 | 55 | break; |
| 55 | 56 | } |
| 56 | 57 | } |
| ... | ... | @@ -86,9 +87,9 @@ export default { |
| 86 | 87 | }); |
| 87 | 88 | }, |
| 88 | 89 | unbind(socialUser) { |
| 89 | - socialUnbind(socialUser.type, socialUser.unionId).then(resp => { | |
| 90 | + socialUnbind(socialUser.type, socialUser.openid).then(resp => { | |
| 90 | 91 | this.$modal.msgSuccess("解绑成功"); |
| 91 | - socialUser.unionId = undefined; | |
| 92 | + socialUser.openid = undefined; | |
| 92 | 93 | }); |
| 93 | 94 | }, |
| 94 | 95 | close() { | ... | ... |