进一步重构社交登陆的实现

This commit is contained in:
YunaiV 2022-04-26 23:36:26 +08:00
parent 878445a238
commit 7227664f77
21 changed files with 155 additions and 134 deletions

View File

@ -1,6 +1,9 @@
package cn.iocoder.yudao.framework.social.config; package cn.iocoder.yudao.framework.social.config;
import cn.hutool.core.util.ReflectUtil;
import cn.iocoder.yudao.framework.social.core.YudaoAuthRequestFactory; import cn.iocoder.yudao.framework.social.core.YudaoAuthRequestFactory;
import com.xkcoding.http.HttpUtil;
import com.xkcoding.http.support.hutool.HutoolImpl;
import com.xkcoding.justauth.autoconfigure.JustAuthProperties; import com.xkcoding.justauth.autoconfigure.JustAuthProperties;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.cache.AuthStateCache; import me.zhyd.oauth.cache.AuthStateCache;
@ -23,6 +26,9 @@ public class YudaoSocialAutoConfiguration {
@Bean @Bean
@ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true) @ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true)
public YudaoAuthRequestFactory yudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { public YudaoAuthRequestFactory yudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) {
// 需要修改 HttpUtil 使用的实现避免类报错
HttpUtil.setHttp(new HutoolImpl());
// 创建 YudaoAuthRequestFactory
return new YudaoAuthRequestFactory(properties, authStateCache); return new YudaoAuthRequestFactory(properties, authStateCache);
} }

View File

@ -36,7 +36,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
@Api(tags = "管理后台 - 认证") @Api(tags = "管理后台 - 认证")
@RestController @RestController
@RequestMapping("/system") // 暂时不跟 /auth 结尾 @RequestMapping("/system/auth") // 暂时不跟 /auth 结尾
@Validated @Validated
@Slf4j @Slf4j
public class AuthController { public class AuthController {
@ -80,7 +80,7 @@ public class AuthController {
return success(AuthConvert.INSTANCE.convert(user, roleList, menuList)); return success(AuthConvert.INSTANCE.convert(user, roleList, menuList));
} }
@GetMapping("list-menus") @GetMapping("/list-menus")
@ApiOperation("获得登录用户的菜单列表") @ApiOperation("获得登录用户的菜单列表")
public CommonResult<List<AuthMenuRespVO>> getMenus() { public CommonResult<List<AuthMenuRespVO>> getMenus() {
// 获得用户拥有的菜单列表 // 获得用户拥有的菜单列表
@ -105,36 +105,22 @@ public class AuthController {
return CommonResult.success(socialUserService.getAuthorizeUrl(type, redirectUri)); return CommonResult.success(socialUserService.getAuthorizeUrl(type, redirectUri));
} }
@PostMapping("/social-login") @PostMapping("/social-quick-login")
@ApiOperation("社交登录,使用 code 授权码") @ApiOperation("社交快捷登录,使用 code 授权码")
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志 @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
public CommonResult<AuthLoginRespVO> socialLogin(@RequestBody @Valid AuthSocialLoginReqVO reqVO) { public CommonResult<AuthLoginRespVO> socialQuickLogin(@RequestBody @Valid AuthSocialQuickLoginReqVO reqVO) {
String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent()); String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent());
// 返回结果 // 返回结果
return success(AuthLoginRespVO.builder().token(token).build()); return success(AuthLoginRespVO.builder().token(token).build());
} }
@PostMapping("/social-login2") @PostMapping("/social-bind-login")
@ApiOperation("社交登录,使用 code 授权码 + 账号密码") @ApiOperation("社交绑定登录,使用 code 授权码 + 账号密码")
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志 @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
public CommonResult<AuthLoginRespVO> socialLogin2(@RequestBody @Valid AuthSocialLogin2ReqVO reqVO) { public CommonResult<AuthLoginRespVO> socialBindLogin(@RequestBody @Valid AuthSocialBindLoginReqVO reqVO) {
String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent()); String token = authService.socialBindLogin(reqVO, getClientIP(), getUserAgent());
// 返回结果 // 返回结果
return success(AuthLoginRespVO.builder().token(token).build()); return success(AuthLoginRespVO.builder().token(token).build());
} }
@PostMapping("/social-bind")
@ApiOperation("社交绑定,使用 code 授权码")
public CommonResult<Boolean> socialBind(@RequestBody @Valid AuthSocialBindReqVO reqVO) {
authService.socialBind(getLoginUserId(), reqVO);
return CommonResult.success(true);
}
@DeleteMapping("/social-unbind")
@ApiOperation("取消社交绑定")
public CommonResult<Boolean> socialUnbind(@RequestBody AuthSocialUnbindReqVO reqVO) {
socialUserService.unbindSocialUser(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getUnionId());
return CommonResult.success(true);
}
} }

View File

@ -14,12 +14,12 @@ import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
@ApiModel("管理后台 - 社交登录 Request VO使用 code 授权码 + 账号密码") @ApiModel("管理后台 - 社交绑定登录 Request VO使用 code 授权码 + 账号密码")
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class AuthSocialLogin2ReqVO { public class AuthSocialBindLoginReqVO {
@ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 UserSocialTypeEnum 枚举值") @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 UserSocialTypeEnum 枚举值")
@InEnum(SocialTypeEnum.class) @InEnum(SocialTypeEnum.class)

View File

@ -12,12 +12,12 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ApiModel("管理后台 - 社交登录 Request VO使用 code 授权码") @ApiModel("管理后台 - 社交快捷登录 Request VO使用 code 授权码")
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class AuthSocialLoginReqVO { public class AuthSocialQuickLoginReqVO {
@ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 UserSocialTypeEnum 枚举值") @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 UserSocialTypeEnum 枚举值")
@InEnum(SocialTypeEnum.class) @InEnum(SocialTypeEnum.class)

View File

@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.system.controller.admin.socail;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialUnbindReqVO;
import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert;
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Api(tags = "管理后台 - 社交用户")
@RestController
@RequestMapping("/system/social-user")
@Validated
public class SocialUserController {
@Resource
private SocialUserService socialUserService;
@PostMapping("/bind")
@ApiOperation("社交绑定,使用 code 授权码")
public CommonResult<Boolean> socialBind(@RequestBody @Valid AuthSocialBindReqVO reqVO) {
socialUserService.bindSocialUser(SocialUserConvert.INSTANCE.convert(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO));
return CommonResult.success(true);
}
@DeleteMapping("/unbind")
@ApiOperation("取消社交绑定")
public CommonResult<Boolean> socialUnbind(@RequestBody AuthSocialUnbindReqVO reqVO) {
socialUserService.unbindSocialUser(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getUnionId());
return CommonResult.success(true);
}
}

View File

@ -96,8 +96,8 @@ public class UserProfileRespVO extends UserBaseVO {
@ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SocialTypeEnum 枚举类") @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SocialTypeEnum 枚举类")
private Integer type; private Integer type;
@ApiModelProperty(value = "社交的全局编号", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") @ApiModelProperty(value = "社交用户的 openid", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE")
private String unionId; private String openid;
} }

View File

@ -72,9 +72,8 @@ public interface AuthConvert {
return CollectionUtils.filterList(treeNodeMap.values(), node -> MenuIdEnum.ROOT.getId().equals(node.getParentId())); return CollectionUtils.filterList(treeNodeMap.values(), node -> MenuIdEnum.ROOT.getId().equals(node.getParentId()));
} }
SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialBindReqVO reqVO); SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialBindLoginReqVO reqVO);
SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLogin2ReqVO reqVO);
SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLoginReqVO reqVO); SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialQuickLoginReqVO reqVO);
SocialUserUnbindReqDTO convert(Long userId, Integer userType, AuthSocialUnbindReqVO reqVO);
} }

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.system.convert.social;
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialUnbindReqVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface SocialUserConvert {
SocialUserConvert INSTANCE = Mappers.getMapper(SocialUserConvert.class);
SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialBindReqVO reqVO);
SocialUserUnbindReqDTO convert(Long userId, Integer userType, AuthSocialUnbindReqVO reqVO);
}

View File

@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.dal.dataobject.social;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*; import lombok.*;

View File

@ -18,14 +18,18 @@ public class SecurityConfiguration {
@Override @Override
public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) { public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {
// 登录的接口可匿名访问 // 登录的接口
registry.antMatchers(buildAdminApi("/system/login")).anonymous(); registry.antMatchers(buildAdminApi("/system/auth/login")).permitAll();
// 社交登陆的接口
registry.antMatchers(buildAdminApi("/system/auth/social-auth-redirect")).permitAll();
registry.antMatchers(buildAdminApi("/system/auth/social-quick-login")).permitAll();
registry.antMatchers(buildAdminApi("/system/auth/social-bind-login")).permitAll();
// 验证码的接口 // 验证码的接口
registry.antMatchers(buildAdminApi("/system/captcha/**")).anonymous(); registry.antMatchers(buildAdminApi("/system/captcha/**")).permitAll();
// 获得租户编号的接口 // 获得租户编号的接口
registry.antMatchers(buildAdminApi("/system/tenant/get-id-by-name")).anonymous(); registry.antMatchers(buildAdminApi("/system/tenant/get-id-by-name")).permitAll();
// 短信回调 API // 短信回调 API
registry.antMatchers(buildAdminApi("/system/sms/callback/**")).anonymous(); registry.antMatchers(buildAdminApi("/system/sms/callback/**")).permitAll();
} }
}; };

View File

@ -25,31 +25,23 @@ public interface AdminAuthService extends SecurityAuthFrameworkService {
String login(@Valid AuthLoginReqVO reqVO, String userIp, String userAgent); String login(@Valid AuthLoginReqVO reqVO, String userIp, String userAgent);
/** /**
* 社交登录使用 code 授权码 * 社交快捷登录使用 code 授权码
* *
* @param reqVO 登录信息 * @param reqVO 登录信息
* @param userIp 用户 IP * @param userIp 用户 IP
* @param userAgent 用户 UA * @param userAgent 用户 UA
* @return 身份令牌使用 JWT 方式 * @return 身份令牌使用 JWT 方式
*/ */
String socialLogin(@Valid AuthSocialLoginReqVO reqVO, String userIp, String userAgent); String socialLogin(@Valid AuthSocialQuickLoginReqVO reqVO, String userIp, String userAgent);
/** /**
* 社交登录使用 code 授权码 + 账号密码 * 社交绑定登录使用 code 授权码 + 账号密码
* *
* @param reqVO 登录信息 * @param reqVO 登录信息
* @param userIp 用户 IP * @param userIp 用户 IP
* @param userAgent 用户 UA * @param userAgent 用户 UA
* @return 身份令牌使用 JWT 方式 * @return 身份令牌使用 JWT 方式
*/ */
String socialLogin2(@Valid AuthSocialLogin2ReqVO reqVO, String userIp, String userAgent); String socialBindLogin(@Valid AuthSocialBindLoginReqVO reqVO, String userIp, String userAgent);
/**
* 社交绑定使用 code 授权码
*
* @param userId 用户编号
* @param reqVO 绑定信息
*/
void socialBind(Long userId, @Valid AuthSocialBindReqVO reqVO);
} }

View File

@ -9,9 +9,9 @@ import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.authentication.MultiUsernamePasswordAuthenticationToken; import cn.iocoder.yudao.framework.security.core.authentication.MultiUsernamePasswordAuthenticationToken;
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthLoginReqVO; import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthLoginReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindLoginReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialLogin2ReqVO; import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialQuickLoginReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialLoginReqVO;
import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
@ -22,7 +22,6 @@ import cn.iocoder.yudao.module.system.service.permission.PermissionService;
import cn.iocoder.yudao.module.system.service.social.SocialUserService; import cn.iocoder.yudao.module.system.service.social.SocialUserService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService; import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.model.AuthUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
@ -82,7 +81,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
throw new UsernameNotFoundException(username); throw new UsernameNotFoundException(username);
} }
// 创建 LoginUser 对象 // 创建 LoginUser 对象
return this.buildLoginUser(user); return buildLoginUser(user);
} }
@Override @Override
@ -92,19 +91,19 @@ public class AdminAuthServiceImpl implements AdminAuthService {
if (user == null) { if (user == null) {
throw new UsernameNotFoundException(String.valueOf(userId)); throw new UsernameNotFoundException(String.valueOf(userId));
} }
this.createLoginLog(user.getUsername(), LoginLogTypeEnum.LOGIN_MOCK, LoginResultEnum.SUCCESS); createLoginLog(user.getUsername(), LoginLogTypeEnum.LOGIN_MOCK, LoginResultEnum.SUCCESS);
// 创建 LoginUser 对象 // 创建 LoginUser 对象
return this.buildLoginUser(user); return buildLoginUser(user);
} }
@Override @Override
public String login(AuthLoginReqVO reqVO, String userIp, String userAgent) { public String login(AuthLoginReqVO reqVO, String userIp, String userAgent) {
// 判断验证码是否正确 // 判断验证码是否正确
this.verifyCaptcha(reqVO); verifyCaptcha(reqVO);
// 使用账号密码进行登录 // 使用账号密码进行登录
LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); LoginUser loginUser = login0(reqVO.getUsername(), reqVO.getPassword());
// 缓存登陆用户到 Redis 返回 sessionId 编号 // 缓存登陆用户到 Redis 返回 sessionId 编号
return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_USERNAME, userIp, userAgent); return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_USERNAME, userIp, userAgent);
@ -192,7 +191,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
} }
@Override @Override
public String socialLogin(AuthSocialLoginReqVO reqVO, String userIp, String userAgent) { public String socialLogin(AuthSocialQuickLoginReqVO reqVO, String userIp, String userAgent) {
// 使用 code 授权码进行登录然后获得到绑定的用户编号 // 使用 code 授权码进行登录然后获得到绑定的用户编号
Long userId = socialUserService.getBindUserId(UserTypeEnum.ADMIN.getValue(), reqVO.getType(), Long userId = socialUserService.getBindUserId(UserTypeEnum.ADMIN.getValue(), reqVO.getType(),
reqVO.getCode(), reqVO.getState()); reqVO.getCode(), reqVO.getState());
@ -207,24 +206,18 @@ public class AdminAuthServiceImpl implements AdminAuthService {
} }
// 创建 LoginUser 对象 // 创建 LoginUser 对象
LoginUser loginUser = this.buildLoginUser(user); LoginUser loginUser = buildLoginUser(user);
// 绑定社交用户更新
socialUserService.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO));
// 缓存登录用户到 Redis 返回 sessionId 编号 // 缓存登录用户到 Redis 返回 sessionId 编号
return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_SOCIAL, userIp, userAgent); return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_SOCIAL, userIp, userAgent);
} }
@Override @Override
public String socialLogin2(AuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { public String socialBindLogin(AuthSocialBindLoginReqVO reqVO, String userIp, String userAgent) {
// 使用 code 授权码进行登录
socialUserService.authSocialUser(reqVO.getType(), reqVO.getCode(), reqVO.getState());
// 使用账号密码进行登录 // 使用账号密码进行登录
LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); LoginUser loginUser = login0(reqVO.getUsername(), reqVO.getPassword());
// 绑定社交用户新增 // 绑定社交用户
socialUserService.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO)); socialUserService.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO));
// 缓存登录用户到 Redis 返回 sessionId 编号 // 缓存登录用户到 Redis 返回 sessionId 编号
@ -238,12 +231,6 @@ public class AdminAuthServiceImpl implements AdminAuthService {
return userSessionService.createUserSession(loginUser, userIp, userAgent); return userSessionService.createUserSession(loginUser, userIp, userAgent);
} }
@Override
public void socialBind(Long userId, AuthSocialBindReqVO reqVO) {
// 绑定社交用户新增
socialUserService.bindSocialUser(AuthConvert.INSTANCE.convert(userId, getUserType().getValue(), reqVO));
}
@Override @Override
public void logout(String token) { public void logout(String token) {
// 查询用户信息 // 查询用户信息

View File

@ -186,10 +186,6 @@ yudao:
justauth: justauth:
enabled: true enabled: true
type: type:
GITEE: # Gitee
client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1
client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9
ignore-check-redirect-uri: true
DINGTALK: # 钉钉 DINGTALK: # 钉钉
client-id: dingvrnreaje3yqvzhxg client-id: dingvrnreaje3yqvzhxg
client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI

View File

@ -196,10 +196,6 @@ yudao:
justauth: justauth:
enabled: true enabled: true
type: type:
GITEE: # Gitee
client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1
client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9
ignore-check-redirect-uri: true
DINGTALK: # 钉钉 DINGTALK: # 钉钉
client-id: dingvrnreaje3yqvzhxg client-id: dingvrnreaje3yqvzhxg
client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI

View File

@ -9,7 +9,7 @@ export function login(username, password, code, uuid) {
uuid uuid
} }
return request({ return request({
url: '/system/login', url: '/system/auth/login',
method: 'post', method: 'post',
data: data data: data
}) })
@ -18,7 +18,7 @@ export function login(username, password, code, uuid) {
// 获取用户详细信息 // 获取用户详细信息
export function getInfo() { export function getInfo() {
return request({ return request({
url: '/system/get-permission-info', url: '/system/auth/get-permission-info',
method: 'get' method: 'get'
}) })
} }
@ -43,15 +43,15 @@ export function getCodeImg() {
// 社交授权的跳转 // 社交授权的跳转
export function socialAuthRedirect(type, redirectUri) { export function socialAuthRedirect(type, redirectUri) {
return request({ return request({
url: '/system/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri, url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri,
method: 'get' method: 'get'
}) })
} }
// 社交登录,使用 code 授权码 // 社交快捷登录,使用 code 授权码
export function socialLogin(type, code, state) { export function socialQuickLogin(type, code, state) {
return request({ return request({
url: '/system/social-login', url: '/system/auth/social-quick-login',
method: 'post', method: 'post',
data: { data: {
type, type,
@ -61,10 +61,10 @@ export function socialLogin(type, code, state) {
}) })
} }
// 社交登录,使用 code 授权码 + + 账号密码 // 社交绑定登录,使用 code 授权码 + + 账号密码
export function socialLogin2(type, code, state, username, password) { export function socialBindLogin(type, code, state, username, password) {
return request({ return request({
url: '/system/social-login2', url: '/system/auth/social-bind-login',
method: 'post', method: 'post',
data: { data: {
type, type,
@ -75,28 +75,3 @@ export function socialLogin2(type, code, state, username, password) {
} }
}) })
} }
// 社交绑定,使用 code 授权码
export function socialBind(type, code, state) {
return request({
url: '/system/social-bind',
method: 'post',
data: {
type,
code,
state,
}
})
}
// 取消社交绑定
export function socialUnbind(type, unionId) {
return request({
url: '/system/social-unbind',
method: 'delete',
data: {
type,
unionId
}
})
}

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 获取路由 // 获取路由
export const getRouters = () => { export const getRouters = () => {
return request({ return request({
url: '/system/list-menus', url: '/system/auth/list-menus',
method: 'get' method: 'get'
}) })
} }

View File

@ -0,0 +1,26 @@
import request from "@/utils/request";
// 社交绑定,使用 code 授权码
export function socialBind(type, code, state) {
return request({
url: '/system/social-user/bind',
method: 'post',
data: {
type,
code,
state,
}
})
}
// 取消社交绑定
export function socialUnbind(type, unionId) {
return request({
url: '/system/social-user/unbind',
method: 'delete',
data: {
type,
unionId
}
})
}

View File

@ -1,4 +1,4 @@
import {login, logout, getInfo, socialLogin, socialLogin2} from '@/api/login' import {login, logout, getInfo, socialQuickLogin, socialBindLogin} from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth' import { getToken, setToken, removeToken } from '@/utils/auth'
const user = { const user = {
@ -57,7 +57,7 @@ const user = {
const state = userInfo.state const state = userInfo.state
const type = userInfo.type const type = userInfo.type
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
socialLogin(type, code, state).then(res => { socialQuickLogin(type, code, state).then(res => {
res = res.data; res = res.data;
setToken(res.token) setToken(res.token)
commit('SET_TOKEN', res.token) commit('SET_TOKEN', res.token)
@ -76,7 +76,7 @@ const user = {
const username = userInfo.username.trim() const username = userInfo.username.trim()
const password = userInfo.password const password = userInfo.password
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
socialLogin2(type, code, state, username, password).then(res => { socialBindLogin(type, code, state, username, password).then(res => {
res = res.data; res = res.data;
setToken(res.token) setToken(res.token)
commit('SET_TOKEN', res.token) commit('SET_TOKEN', res.token)

View File

@ -71,12 +71,6 @@ export const InfraApiErrorLogProcessStatusEnum = {
* 用户的社交平台的类型枚举 * 用户的社交平台的类型枚举
*/ */
export const SystemUserSocialTypeEnum = { export const SystemUserSocialTypeEnum = {
// GITEE: {
// title: "码云",
// type: 10,
// source: "gitee",
// img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.11/gitee.png",
// },
DINGTALK: { DINGTALK: {
title: "钉钉", title: "钉钉",
type: 20, type: 20,

View File

@ -176,7 +176,6 @@ export default {
}); });
}, },
doSocialLogin(socialTypeEnum) { doSocialLogin(socialTypeEnum) {
// console.log("Oauth...%o", socialTypeEnum.code);
// //
this.loading = true; this.loading = true;
// redirectUri // redirectUri

View File

@ -7,7 +7,7 @@
</el-table-column> </el-table-column>
<el-table-column label="操作" align="left" > <el-table-column label="操作" align="left" >
<template slot-scope="scope"> <template slot-scope="scope">
<div v-if="scope.row.unionId"> <div v-if="scope.row.openid">
已绑定 已绑定
<el-button size="large" type="text" @click="unbind(scope.row)">(解绑)</el-button> <el-button size="large" type="text" @click="unbind(scope.row)">(解绑)</el-button>
</div> </div>
@ -23,7 +23,8 @@
<script> <script>
import {SystemUserSocialTypeEnum} from "@/utils/constants"; import {SystemUserSocialTypeEnum} from "@/utils/constants";
import {socialAuthRedirect, socialBind, socialUnbind} from "@/api/login"; import {socialAuthRedirect} from "@/api/login";
import {socialBind, socialUnbind} from "@/api/system/socialUser";
export default { export default {
props: { props: {
@ -50,7 +51,7 @@ export default {
if (this.user.socialUsers) { if (this.user.socialUsers) {
for (const j in this.user.socialUsers) { for (const j in this.user.socialUsers) {
if (socialUser.type === this.user.socialUsers[j].type) { if (socialUser.type === this.user.socialUsers[j].type) {
socialUser.unionId = this.user.socialUsers[j].unionId; socialUser.openid = this.user.socialUsers[j].openid;
break; break;
} }
} }
@ -86,9 +87,9 @@ export default {
}); });
}, },
unbind(socialUser) { unbind(socialUser) {
socialUnbind(socialUser.type, socialUser.unionId).then(resp => { socialUnbind(socialUser.type, socialUser.openid).then(resp => {
this.$modal.msgSuccess("解绑成功"); this.$modal.msgSuccess("解绑成功");
socialUser.unionId = undefined; socialUser.openid = undefined;
}); });
}, },
close() { close() {