Procházet zdrojové kódy

1、解决授权问题

rayson před 3 měsíci
rodič
revize
2b1c6d1b14

+ 1 - 1
citu-module-system/citu-module-system-biz/src/main/java/com/citu/module/system/dal/mysql/social/SocialClientMapper.java

@@ -15,7 +15,7 @@ public interface SocialClientMapper extends BaseMapperX<SocialClientDO> {
                 .eqIfPresent(SocialClientDO::getApplication, application)
                 .eq(SocialClientDO::getSocialType, socialType)
                 .eq(SocialClientDO::getUserType, userType)
-                .orderByDesc(SocialClientDO::getCreateTime)
+                .orderByAsc(SocialClientDO::getCreateTime)
                 .last("limit 1")
         );
     }

+ 5 - 5
citu-module-system/citu-module-system-biz/src/main/java/com/citu/module/system/service/social/SocialUserServiceImpl.java

@@ -62,7 +62,7 @@ public class SocialUserServiceImpl implements SocialUserService {
     @Transactional(rollbackFor = Exception.class)
     public String bindSocialUser(SocialUserBindReqDTO reqDTO) {
         // 获得社交用户
-        SocialUserDO socialUser = authSocialUser(reqDTO.getSocialType(), reqDTO.getUserType(),
+        SocialUserDO socialUser = authSocialUser(reqDTO.getApplication(),reqDTO.getSocialType(), reqDTO.getUserType(),
                 reqDTO.getCode(), reqDTO.getState());
         Assert.notNull(socialUser, "社交用户不能为空");
 
@@ -110,7 +110,7 @@ public class SocialUserServiceImpl implements SocialUserService {
     @Override
     public SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state) {
         // 获得社交用户
-        SocialUserDO socialUser = authSocialUser(socialType, userType, code, state);
+        SocialUserDO socialUser = authSocialUser(null,socialType, userType, code, state);
         Assert.notNull(socialUser, "社交用户不能为空");
 
         // 获得绑定用户
@@ -124,7 +124,7 @@ public class SocialUserServiceImpl implements SocialUserService {
     public SocialUserRespDTO getSocialUserByApplicationCode(String application, String code, String state) {
         SocialClientDO socialClient = socialClientService.getSocialClientByApplication(application);
         // 获得社交用户
-        SocialUserDO socialUser = authSocialUser(socialClient.getSocialType(), socialClient.getUserType(), code, state);
+        SocialUserDO socialUser = authSocialUser(application,socialClient.getSocialType(), socialClient.getUserType(), code, state);
         Assert.notNull(socialUser, "社交用户不能为空");
         // 获得绑定用户
         SocialUserBindDO socialUserBind = socialUserBindMapper.selectByUserTypeAndSocialUserId(socialClient.getUserType(),
@@ -161,7 +161,7 @@ public class SocialUserServiceImpl implements SocialUserService {
      * @return 授权用户
      */
     @NotNull
-    public SocialUserDO authSocialUser(Integer socialType, Integer userType, String code, String state) {
+    public SocialUserDO authSocialUser(String application,Integer socialType, Integer userType, String code, String state) {
         // 优先从 DB 中获取,因为 code 有且可以使用一次。
         // 在社交登录时,当未绑定 User 时,需要绑定登录,此时需要 code 使用两次
         SocialUserDO socialUser = socialUserMapper.selectByTypeAndCodeAnState(socialType, code, state);
@@ -170,7 +170,7 @@ public class SocialUserServiceImpl implements SocialUserService {
         }
 
         // 请求获取
-        AuthUser authUser = socialClientService.getAuthUser(null, socialType, userType, code, state);
+        AuthUser authUser = socialClientService.getAuthUser(application, socialType, userType, code, state);
         Assert.notNull(authUser, "三方用户不能为空");
 
         // 保存到 DB 中

+ 4 - 4
citu-module-system/citu-module-system-biz/src/test/java/com/citu/module/system/service/social/SocialUserServiceImplTest.java

@@ -165,7 +165,7 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
         socialUserMapper.insert(socialUser);
 
         // 调用
-        SocialUserDO result = socialUserService.authSocialUser(socialType, userType, code, state);
+        SocialUserDO result = socialUserService.authSocialUser(null,socialType, userType, code, state);
         // 断言
         assertPojoEquals(socialUser, result);
     }
@@ -183,7 +183,7 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
         String state = "yuanma";
 
         // 调用
-        SocialUserDO result = socialUserService.authSocialUser(socialType, userType, code, state);
+        SocialUserDO result = socialUserService.authSocialUser(null,socialType, userType, code, state);
         // 断言
         assertPojoEquals(socialUser, result);
     }
@@ -200,7 +200,7 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
         when(socialClientService.getAuthUser(null,eq(socialType), eq(userType), eq(code), eq(state))).thenReturn(authUser);
 
         // 调用
-        SocialUserDO result = socialUserService.authSocialUser(socialType, userType, code, state);
+        SocialUserDO result = socialUserService.authSocialUser(null,socialType, userType, code, state);
         // 断言
         assertBindSocialUser(socialType, result, authUser);
         assertEquals(code, result.getCode());
@@ -221,7 +221,7 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
         when(socialClientService.getAuthUser(null,eq(socialType), eq(userType), eq(code), eq(state))).thenReturn(authUser);
 
         // 调用
-        SocialUserDO result = socialUserService.authSocialUser(socialType, userType, code, state);
+        SocialUserDO result = socialUserService.authSocialUser(null,socialType, userType, code, state);
         // 断言
         assertBindSocialUser(socialType, result, authUser);
         assertEquals(code, result.getCode());