Commit 65abc667b03086fe321fe13f0149fad61058a994
1 parent
8aa45406
code review 社交登陆相关的代码
Showing
6 changed files
with
13 additions
and
11 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java
| @@ -50,7 +50,7 @@ public class SysAuthController { | @@ -50,7 +50,7 @@ public class SysAuthController { | ||
| 50 | @Resource | 50 | @Resource |
| 51 | private SysPermissionService permissionService; | 51 | private SysPermissionService permissionService; |
| 52 | @Resource | 52 | @Resource |
| 53 | - private SysSocialCoreService socialService; | 53 | + private SysSocialCoreService socialCoreService; |
| 54 | 54 | ||
| 55 | @PostMapping("/login") | 55 | @PostMapping("/login") |
| 56 | @ApiOperation("使用账号密码登录") | 56 | @ApiOperation("使用账号密码登录") |
| @@ -102,7 +102,7 @@ public class SysAuthController { | @@ -102,7 +102,7 @@ public class SysAuthController { | ||
| 102 | }) | 102 | }) |
| 103 | public CommonResult<String> socialAuthRedirect(@RequestParam("type") Integer type, | 103 | public CommonResult<String> socialAuthRedirect(@RequestParam("type") Integer type, |
| 104 | @RequestParam("redirectUri") String redirectUri) { | 104 | @RequestParam("redirectUri") String redirectUri) { |
| 105 | - return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri)); | 105 | + return CommonResult.success(socialCoreService.getAuthorizeUrl(type, redirectUri)); |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | @PostMapping("/social-login") | 108 | @PostMapping("/social-login") |
| @@ -133,7 +133,7 @@ public class SysAuthController { | @@ -133,7 +133,7 @@ public class SysAuthController { | ||
| 133 | @DeleteMapping("/social-unbind") | 133 | @DeleteMapping("/social-unbind") |
| 134 | @ApiOperation("取消社交绑定") | 134 | @ApiOperation("取消社交绑定") |
| 135 | public CommonResult<Boolean> socialUnbind(@RequestBody SysAuthSocialUnbindReqVO reqVO) { | 135 | public CommonResult<Boolean> socialUnbind(@RequestBody SysAuthSocialUnbindReqVO reqVO) { |
| 136 | - socialService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId(), UserTypeEnum.ADMIN); | 136 | + socialCoreService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId(), UserTypeEnum.ADMIN); |
| 137 | return CommonResult.success(true); | 137 | return CommonResult.success(true); |
| 138 | } | 138 | } |
| 139 | 139 |
yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java
| 1 | package cn.iocoder.yudao.framework.social.core; | 1 | package cn.iocoder.yudao.framework.social.core; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.EnumUtil; | 3 | import cn.hutool.core.util.EnumUtil; |
| 4 | -import cn.hutool.core.util.StrUtil; | ||
| 5 | import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource; | 4 | import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource; |
| 6 | import cn.iocoder.yudao.framework.social.core.request.AuthWeChatMiniProgramRequest; | 5 | import cn.iocoder.yudao.framework.social.core.request.AuthWeChatMiniProgramRequest; |
| 7 | import com.xkcoding.http.config.HttpConfig; | 6 | import com.xkcoding.http.config.HttpConfig; |
| @@ -18,12 +17,14 @@ import java.net.Proxy; | @@ -18,12 +17,14 @@ import java.net.Proxy; | ||
| 18 | import java.util.Map; | 17 | import java.util.Map; |
| 19 | 18 | ||
| 20 | /** | 19 | /** |
| 21 | - * 第三方授权拓展request工厂类 | 20 | + * 第三方授权拓展 request 工厂类 |
| 21 | + * TODO @timfruit 可以说明下,为啥有了 AuthRequestFactory 类,咱还需要自定义 | ||
| 22 | * | 22 | * |
| 23 | * @author timfruit | 23 | * @author timfruit |
| 24 | * @date 2021-10-31 | 24 | * @date 2021-10-31 |
| 25 | */ | 25 | */ |
| 26 | public class YudaoAuthRequestFactory extends AuthRequestFactory { | 26 | public class YudaoAuthRequestFactory extends AuthRequestFactory { |
| 27 | + | ||
| 27 | protected JustAuthProperties properties; | 28 | protected JustAuthProperties properties; |
| 28 | protected AuthStateCache authStateCache; | 29 | protected AuthStateCache authStateCache; |
| 29 | 30 | ||
| @@ -34,7 +35,7 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { | @@ -34,7 +35,7 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { | ||
| 34 | } | 35 | } |
| 35 | 36 | ||
| 36 | /** | 37 | /** |
| 37 | - * 返回AuthRequest对象 | 38 | + * 返回 AuthRequest 对象 |
| 38 | * | 39 | * |
| 39 | * @param source {@link AuthSource} | 40 | * @param source {@link AuthSource} |
| 40 | * @return {@link AuthRequest} | 41 | * @return {@link AuthRequest} |
| @@ -86,6 +87,7 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { | @@ -86,6 +87,7 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { | ||
| 86 | * @param authConfig {@link AuthConfig} | 87 | * @param authConfig {@link AuthConfig} |
| 87 | */ | 88 | */ |
| 88 | protected void configureHttpConfig(String authSource, AuthConfig authConfig, JustAuthProperties.JustAuthHttpConfig httpConfig) { | 89 | protected void configureHttpConfig(String authSource, AuthConfig authConfig, JustAuthProperties.JustAuthHttpConfig httpConfig) { |
| 90 | + // TODO @timfruit:可以改成反射调用父类的方法。可能有一定的损耗,但是可以忽略不计的 | ||
| 89 | if (null == httpConfig) { | 91 | if (null == httpConfig) { |
| 90 | return; | 92 | return; |
| 91 | } | 93 | } |
yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/enums/AuthExtendSource.java
| @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.social.core.enums; | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.social.core.enums; | ||
| 2 | 2 | ||
| 3 | import me.zhyd.oauth.config.AuthSource; | 3 | import me.zhyd.oauth.config.AuthSource; |
| 4 | 4 | ||
| 5 | +// TODO @timfruit:类注释 | ||
| 5 | public enum AuthExtendSource implements AuthSource { | 6 | public enum AuthExtendSource implements AuthSource { |
| 6 | 7 | ||
| 7 | /** | 8 | /** |
| @@ -28,6 +29,4 @@ public enum AuthExtendSource implements AuthSource { | @@ -28,6 +29,4 @@ public enum AuthExtendSource implements AuthSource { | ||
| 28 | } | 29 | } |
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | - ; | ||
| 32 | - | ||
| 33 | } | 32 | } |
yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/model/AuthExtendToken.java
| @@ -4,7 +4,7 @@ import lombok.*; | @@ -4,7 +4,7 @@ import lombok.*; | ||
| 4 | import me.zhyd.oauth.model.AuthToken; | 4 | import me.zhyd.oauth.model.AuthToken; |
| 5 | 5 | ||
| 6 | /** | 6 | /** |
| 7 | - * 授权所需的token 拓展类 | 7 | + * 授权所需的 token 拓展类 |
| 8 | * | 8 | * |
| 9 | * @author timfruit | 9 | * @author timfruit |
| 10 | * @date 2021-10-29 | 10 | * @date 2021-10-29 |
| @@ -16,7 +16,7 @@ import me.zhyd.oauth.model.AuthToken; | @@ -16,7 +16,7 @@ import me.zhyd.oauth.model.AuthToken; | ||
| 16 | public class AuthExtendToken extends AuthToken { | 16 | public class AuthExtendToken extends AuthToken { |
| 17 | 17 | ||
| 18 | /** | 18 | /** |
| 19 | - * 微信小程序 会话密钥 | 19 | + * 微信小程序 - 会话密钥 |
| 20 | */ | 20 | */ |
| 21 | private String miniSessionKey; | 21 | private String miniSessionKey; |
| 22 | 22 |
yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/request/AuthWeChatMiniProgramRequest.java
| @@ -86,6 +86,7 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { | @@ -86,6 +86,7 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { | ||
| 86 | .build(); | 86 | .build(); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | + // TODO @timfruit:我们要采用驼峰的命名方式。不匹配的,可以通过 jackson 的自定义注解映射 | ||
| 89 | @Data | 90 | @Data |
| 90 | private static class CodeSessionResponse { | 91 | private static class CodeSessionResponse { |
| 91 | private int errcode; | 92 | private int errcode; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java
| @@ -65,7 +65,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -65,7 +65,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 65 | private SysUserSessionCoreService userSessionCoreService; | 65 | private SysUserSessionCoreService userSessionCoreService; |
| 66 | @Resource | 66 | @Resource |
| 67 | private SysSocialCoreService socialService; | 67 | private SysSocialCoreService socialService; |
| 68 | - private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.MEMBER; | 68 | + private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.MEMBER; // TODO @timfruit 挪到类的最前面。一般是 静态变量,到成员变量的顺序。 |
| 69 | 69 | ||
| 70 | @Override | 70 | @Override |
| 71 | public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException { | 71 | public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException { |