Commit 55e5ca4644293afc0d2f5edf3cd272cdef6df01c
1 parent
30ad7c43
code review 用户前台的社交登陆
Showing
11 changed files
with
20 additions
and
12 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java
| @@ -75,6 +75,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -75,6 +75,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 75 | @Resource | 75 | @Resource |
| 76 | private SysSocialService socialService; | 76 | private SysSocialService socialService; |
| 77 | 77 | ||
| 78 | + // TODO @timfruit:静态枚举类,需要都大写,例如说 USER_TYPE_ENUM;静态变量,放在普通变量前面;这个实践不错哈。 | ||
| 78 | private static final UserTypeEnum userTypeEnum = UserTypeEnum.ADMIN; | 79 | private static final UserTypeEnum userTypeEnum = UserTypeEnum.ADMIN; |
| 79 | 80 | ||
| 80 | @Override | 81 | @Override |
| @@ -214,7 +215,6 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -214,7 +215,6 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 214 | 215 | ||
| 215 | // 创建 LoginUser 对象 | 216 | // 创建 LoginUser 对象 |
| 216 | LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); | 217 | LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); |
| 217 | - // TODO 芋艿:需要改造下,增加各种登录方式 | ||
| 218 | loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 | 218 | loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 |
| 219 | 219 | ||
| 220 | // 绑定社交用户(更新) | 220 | // 绑定社交用户(更新) |
yudao-core-service/pom.xml
| @@ -86,11 +86,12 @@ | @@ -86,11 +86,12 @@ | ||
| 86 | <artifactId>guava</artifactId> | 86 | <artifactId>guava</artifactId> |
| 87 | </dependency> | 87 | </dependency> |
| 88 | 88 | ||
| 89 | + <!-- 三方云服务相关 --> | ||
| 89 | <dependency> | 90 | <dependency> |
| 90 | <groupId>com.xkcoding.justauth</groupId> | 91 | <groupId>com.xkcoding.justauth</groupId> |
| 91 | <artifactId>justauth-spring-boot-starter</artifactId> | 92 | <artifactId>justauth-spring-boot-starter</artifactId> |
| 92 | - <version>1.4.0</version> | ||
| 93 | </dependency> | 93 | </dependency> |
| 94 | + | ||
| 94 | </dependencies> | 95 | </dependencies> |
| 95 | 96 | ||
| 96 | </project> | 97 | </project> |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/social/SysSocialUserMapper.java
| @@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Mapper; | @@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Mapper; | ||
| 8 | import java.util.Collection; | 8 | import java.util.Collection; |
| 9 | import java.util.List; | 9 | import java.util.List; |
| 10 | 10 | ||
| 11 | +// TODO @timfruit:SysSocialUserCoreMapper 改名,方便区分 | ||
| 11 | @Mapper | 12 | @Mapper |
| 12 | public interface SysSocialUserMapper extends BaseMapperX<SysSocialUserDO> { | 13 | public interface SysSocialUserMapper extends BaseMapperX<SysSocialUserDO> { |
| 13 | 14 |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/SysRedisKeyCoreConstants.java
| @@ -19,11 +19,11 @@ public interface SysRedisKeyCoreConstants { | @@ -19,11 +19,11 @@ public interface SysRedisKeyCoreConstants { | ||
| 19 | "login_user:%s", // 参数为 sessionId | 19 | "login_user:%s", // 参数为 sessionId |
| 20 | STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); | 20 | STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); |
| 21 | 21 | ||
| 22 | - RedisKeyDefine SOCIAL_AUTH_USER = new RedisKeyDefine("社交的授权用户", | 22 | + RedisKeyDefine SOCIAL_AUTH_USER = new RedisKeyDefine("社交登陆的授权用户", |
| 23 | "social_auth_user:%d:%s", // 参数为 type,code | 23 | "social_auth_user:%d:%s", // 参数为 type,code |
| 24 | STRING, AuthUser.class, Duration.ofDays(1)); | 24 | STRING, AuthUser.class, Duration.ofDays(1)); |
| 25 | 25 | ||
| 26 | - RedisKeyDefine SOCIAL_AUTH_STATE = new RedisKeyDefine("社交的 state", | 26 | + RedisKeyDefine SOCIAL_AUTH_STATE = new RedisKeyDefine("社交登陆的 state", |
| 27 | "social_auth_state:%s", // 参数为 state | 27 | "social_auth_state:%s", // 参数为 state |
| 28 | STRING, String.class, Duration.ofHours(24)); // 值为 state | 28 | STRING, String.class, Duration.ofHours(24)); // 值为 state |
| 29 | } | 29 | } |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/social/SysSocialAuthUserRedisDAO.java
| @@ -10,7 +10,7 @@ import javax.annotation.Resource; | @@ -10,7 +10,7 @@ import javax.annotation.Resource; | ||
| 10 | 10 | ||
| 11 | import static cn.iocoder.yudao.coreservice.modules.system.dal.redis.SysRedisKeyCoreConstants.SOCIAL_AUTH_USER; | 11 | import static cn.iocoder.yudao.coreservice.modules.system.dal.redis.SysRedisKeyCoreConstants.SOCIAL_AUTH_USER; |
| 12 | 12 | ||
| 13 | - | 13 | +// TODO @timfruit,这里的 AuthUser 还是保留全路径,主要想体现出来,不是自己定义的 |
| 14 | /** | 14 | /** |
| 15 | * 社交 {@link AuthUser} 的 RedisDAO | 15 | * 社交 {@link AuthUser} 的 RedisDAO |
| 16 | * | 16 | * |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/social/SysSocialTypeEnum.java
| @@ -21,6 +21,7 @@ public enum SysSocialTypeEnum implements IntArrayValuable { | @@ -21,6 +21,7 @@ public enum SysSocialTypeEnum implements IntArrayValuable { | ||
| 21 | GITEE(10, "GITEE"), // https://gitee.com/api/v5/oauth_doc#/ | 21 | GITEE(10, "GITEE"), // https://gitee.com/api/v5/oauth_doc#/ |
| 22 | DINGTALK(20, "DINGTALK"), // https://developers.dingtalk.com/document/app/obtain-identity-credentials | 22 | DINGTALK(20, "DINGTALK"), // https://developers.dingtalk.com/document/app/obtain-identity-credentials |
| 23 | WECHAT_ENTERPRISE(30, "WECHAT_ENTERPRISE"), // https://xkcoding.com/2019/08/06/use-justauth-integration-wechat-enterprise.html | 23 | WECHAT_ENTERPRISE(30, "WECHAT_ENTERPRISE"), // https://xkcoding.com/2019/08/06/use-justauth-integration-wechat-enterprise.html |
| 24 | + // TODO @timfruit:微信平台,从 30 开始递增哈。另外,尽量不要出现,先 12,然后 11,有序,嘿嘿。 | ||
| 24 | /** | 25 | /** |
| 25 | * 微信公众平台 - H5 | 26 | * 微信公众平台 - H5 |
| 26 | */ | 27 | */ |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/social/SysSocialService.java
| @@ -15,6 +15,7 @@ import java.util.List; | @@ -15,6 +15,7 @@ import java.util.List; | ||
| 15 | * | 15 | * |
| 16 | * @author 芋道源码 | 16 | * @author 芋道源码 |
| 17 | */ | 17 | */ |
| 18 | +// TODO @timfruit:SysSocialCoreService 改名,方便区分 | ||
| 18 | public interface SysSocialService { | 19 | public interface SysSocialService { |
| 19 | 20 | ||
| 20 | /** | 21 | /** |
| @@ -77,5 +78,6 @@ public interface SysSocialService { | @@ -77,5 +78,6 @@ public interface SysSocialService { | ||
| 77 | * @param unionId 社交平台的 unionId | 78 | * @param unionId 社交平台的 unionId |
| 78 | */ | 79 | */ |
| 79 | void unbindSocialUser(Long userId, Integer type, String unionId,UserTypeEnum userTypeEnum); | 80 | void unbindSocialUser(Long userId, Integer type, String unionId,UserTypeEnum userTypeEnum); |
| 81 | + // TODO @timfruit:逗号后面要有空格;缺少了 @userTypeEnum 的注释,都补充下哈。 | ||
| 80 | 82 | ||
| 81 | } | 83 | } |
yudao-dependencies/pom.xml
| @@ -52,6 +52,7 @@ | @@ -52,6 +52,7 @@ | ||
| 52 | <aliyun-java-sdk-core.version>4.5.25</aliyun-java-sdk-core.version> | 52 | <aliyun-java-sdk-core.version>4.5.25</aliyun-java-sdk-core.version> |
| 53 | <aliyun-java-sdk-dysmsapi.version>2.1.0</aliyun-java-sdk-dysmsapi.version> | 53 | <aliyun-java-sdk-dysmsapi.version>2.1.0</aliyun-java-sdk-dysmsapi.version> |
| 54 | <yunpian-java-sdk.version>1.2.7</yunpian-java-sdk.version> | 54 | <yunpian-java-sdk.version>1.2.7</yunpian-java-sdk.version> |
| 55 | + <justauth.version>1.4.0</justauth.version> | ||
| 55 | </properties> | 56 | </properties> |
| 56 | 57 | ||
| 57 | <dependencyManagement> | 58 | <dependencyManagement> |
| @@ -399,7 +400,6 @@ | @@ -399,7 +400,6 @@ | ||
| 399 | <artifactId>yunpian-java-sdk</artifactId> | 400 | <artifactId>yunpian-java-sdk</artifactId> |
| 400 | <version>${yunpian-java-sdk.version}</version> | 401 | <version>${yunpian-java-sdk.version}</version> |
| 401 | </dependency> | 402 | </dependency> |
| 402 | - | ||
| 403 | <dependency> | 403 | <dependency> |
| 404 | <groupId>com.aliyun</groupId> | 404 | <groupId>com.aliyun</groupId> |
| 405 | <artifactId>aliyun-java-sdk-core</artifactId> | 405 | <artifactId>aliyun-java-sdk-core</artifactId> |
| @@ -421,6 +421,13 @@ | @@ -421,6 +421,13 @@ | ||
| 421 | <version>${aliyun-java-sdk-dysmsapi.version}</version> | 421 | <version>${aliyun-java-sdk-dysmsapi.version}</version> |
| 422 | </dependency> | 422 | </dependency> |
| 423 | <!-- SMS SDK end --> | 423 | <!-- SMS SDK end --> |
| 424 | + | ||
| 425 | + <dependency> | ||
| 426 | + <groupId>com.xkcoding.justauth</groupId> | ||
| 427 | + <artifactId>justauth-spring-boot-starter</artifactId> <!-- 社交登陆(例如说,个人微信、企业微信等等) --> | ||
| 428 | + <version>${justauth.version}</version> | ||
| 429 | + </dependency> | ||
| 430 | + | ||
| 424 | </dependencies> | 431 | </dependencies> |
| 425 | </dependencyManagement> | 432 | </dependencyManagement> |
| 426 | 433 |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.userserver.modules.system.controller.auth; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.userserver.modules.system.controller.auth; | ||
| 3 | import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; | 3 | import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; |
| 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | -import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; | ||
| 7 | import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.*; | 6 | import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.*; |
| 8 | import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; | 7 | import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; |
| 9 | import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | 8 | import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; |
| @@ -82,6 +81,7 @@ public class SysAuthController { | @@ -82,6 +81,7 @@ public class SysAuthController { | ||
| 82 | return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri)); | 81 | return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri)); |
| 83 | } | 82 | } |
| 84 | 83 | ||
| 84 | + // TODO @timfruit:这个接口,是要删除的么? | ||
| 85 | @GetMapping("/social-login-get") | 85 | @GetMapping("/social-login-get") |
| 86 | @ApiOperation("微信公众号授权回调地址,输出social-login2的必要参数用于测试,使用 code 授权码") | 86 | @ApiOperation("微信公众号授权回调地址,输出social-login2的必要参数用于测试,使用 code 授权码") |
| 87 | @ResponseBody | 87 | @ResponseBody |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java
| @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; | @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.hutool.core.lang.Assert; | 4 | import cn.hutool.core.lang.Assert; |
| 5 | import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | 5 | import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; |
| 6 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO; | 6 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO; |
| 7 | -import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 8 | import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; | 7 | import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; |
| 9 | import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; | 8 | import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; |
| 10 | import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; | 9 | import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; |
| @@ -37,7 +36,6 @@ import org.springframework.stereotype.Service; | @@ -37,7 +36,6 @@ import org.springframework.stereotype.Service; | ||
| 37 | import org.springframework.transaction.annotation.Transactional; | 36 | import org.springframework.transaction.annotation.Transactional; |
| 38 | 37 | ||
| 39 | import javax.annotation.Resource; | 38 | import javax.annotation.Resource; |
| 40 | -import javax.validation.Valid; | ||
| 41 | import java.util.List; | 39 | import java.util.List; |
| 42 | import java.util.Objects; | 40 | import java.util.Objects; |
| 43 | 41 | ||
| @@ -130,8 +128,6 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -130,8 +128,6 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 130 | 128 | ||
| 131 | // 创建 LoginUser 对象 | 129 | // 创建 LoginUser 对象 |
| 132 | LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); | 130 | LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); |
| 133 | - // TODO 芋艿:需要改造下,增加各种登录方式 | ||
| 134 | -// loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 | ||
| 135 | 131 | ||
| 136 | // 绑定社交用户(更新) | 132 | // 绑定社交用户(更新) |
| 137 | socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, userTypeEnum); | 133 | socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, userTypeEnum); |
yudao-user-server/src/main/resources/application-dev.yaml
| @@ -142,7 +142,7 @@ yudao: | @@ -142,7 +142,7 @@ yudao: | ||
| 142 | 142 | ||
| 143 | justauth: | 143 | justauth: |
| 144 | enabled: true | 144 | enabled: true |
| 145 | - type: | 145 | + type: # TODO @timfruit:GITEE、DINGTALK、WECHAT_ENTERPRISE 这个几个,对于用户端是不需要的哈,可以删除噢 |
| 146 | GITEE: # Gitee | 146 | GITEE: # Gitee |
| 147 | client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1 | 147 | client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1 |
| 148 | client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9 | 148 | client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9 |