code review 社交登陆相关的代码

This commit is contained in:
YunaiV 2021-11-02 08:12:37 +08:00
parent 8aa45406fd
commit 65abc667b0
6 changed files with 13 additions and 11 deletions

View File

@ -50,7 +50,7 @@ public class SysAuthController {
@Resource @Resource
private SysPermissionService permissionService; private SysPermissionService permissionService;
@Resource @Resource
private SysSocialCoreService socialService; private SysSocialCoreService socialCoreService;
@PostMapping("/login") @PostMapping("/login")
@ApiOperation("使用账号密码登录") @ApiOperation("使用账号密码登录")
@ -102,7 +102,7 @@ public class SysAuthController {
}) })
public CommonResult<String> socialAuthRedirect(@RequestParam("type") Integer type, public CommonResult<String> socialAuthRedirect(@RequestParam("type") Integer type,
@RequestParam("redirectUri") String redirectUri) { @RequestParam("redirectUri") String redirectUri) {
return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri)); return CommonResult.success(socialCoreService.getAuthorizeUrl(type, redirectUri));
} }
@PostMapping("/social-login") @PostMapping("/social-login")
@ -133,7 +133,7 @@ public class SysAuthController {
@DeleteMapping("/social-unbind") @DeleteMapping("/social-unbind")
@ApiOperation("取消社交绑定") @ApiOperation("取消社交绑定")
public CommonResult<Boolean> socialUnbind(@RequestBody SysAuthSocialUnbindReqVO reqVO) { public CommonResult<Boolean> socialUnbind(@RequestBody SysAuthSocialUnbindReqVO reqVO) {
socialService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId(), UserTypeEnum.ADMIN); socialCoreService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId(), UserTypeEnum.ADMIN);
return CommonResult.success(true); return CommonResult.success(true);
} }

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.framework.social.core; package cn.iocoder.yudao.framework.social.core;
import cn.hutool.core.util.EnumUtil; import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource; import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource;
import cn.iocoder.yudao.framework.social.core.request.AuthWeChatMiniProgramRequest; import cn.iocoder.yudao.framework.social.core.request.AuthWeChatMiniProgramRequest;
import com.xkcoding.http.config.HttpConfig; import com.xkcoding.http.config.HttpConfig;
@ -18,12 +17,14 @@ import java.net.Proxy;
import java.util.Map; import java.util.Map;
/** /**
* 第三方授权拓展request工厂类 * 第三方授权拓展 request 工厂类
* TODO @timfruit 可以说明下为啥有了 AuthRequestFactory 咱还需要自定义
* *
* @author timfruit * @author timfruit
* @date 2021-10-31 * @date 2021-10-31
*/ */
public class YudaoAuthRequestFactory extends AuthRequestFactory { public class YudaoAuthRequestFactory extends AuthRequestFactory {
protected JustAuthProperties properties; protected JustAuthProperties properties;
protected AuthStateCache authStateCache; protected AuthStateCache authStateCache;
@ -34,7 +35,7 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory {
} }
/** /**
* 返回AuthRequest对象 * 返回 AuthRequest 对象
* *
* @param source {@link AuthSource} * @param source {@link AuthSource}
* @return {@link AuthRequest} * @return {@link AuthRequest}
@ -86,6 +87,7 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory {
* @param authConfig {@link AuthConfig} * @param authConfig {@link AuthConfig}
*/ */
protected void configureHttpConfig(String authSource, AuthConfig authConfig, JustAuthProperties.JustAuthHttpConfig httpConfig) { protected void configureHttpConfig(String authSource, AuthConfig authConfig, JustAuthProperties.JustAuthHttpConfig httpConfig) {
// TODO @timfruit可以改成反射调用父类的方法可能有一定的损耗但是可以忽略不计的
if (null == httpConfig) { if (null == httpConfig) {
return; return;
} }

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.social.core.enums;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
// TODO @timfruit类注释
public enum AuthExtendSource implements AuthSource { public enum AuthExtendSource implements AuthSource {
/** /**
@ -28,6 +29,4 @@ public enum AuthExtendSource implements AuthSource {
} }
} }
;
} }

View File

@ -4,7 +4,7 @@ import lombok.*;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
/** /**
* 授权所需的token 拓展类 * 授权所需的 token 拓展类
* *
* @author timfruit * @author timfruit
* @date 2021-10-29 * @date 2021-10-29
@ -16,7 +16,7 @@ import me.zhyd.oauth.model.AuthToken;
public class AuthExtendToken extends AuthToken { public class AuthExtendToken extends AuthToken {
/** /**
* 微信小程序 会话密钥 * 微信小程序 - 会话密钥
*/ */
private String miniSessionKey; private String miniSessionKey;

View File

@ -86,6 +86,7 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest {
.build(); .build();
} }
// TODO @timfruit我们要采用驼峰的命名方式不匹配的可以通过 jackson 的自定义注解映射
@Data @Data
private static class CodeSessionResponse { private static class CodeSessionResponse {
private int errcode; private int errcode;

View File

@ -65,7 +65,7 @@ public class SysAuthServiceImpl implements SysAuthService {
private SysUserSessionCoreService userSessionCoreService; private SysUserSessionCoreService userSessionCoreService;
@Resource @Resource
private SysSocialCoreService socialService; private SysSocialCoreService socialService;
private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.MEMBER; private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.MEMBER; // TODO @timfruit 挪到类的最前面一般是 静态变量到成员变量的顺序
@Override @Override
public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException { public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException {