增加三方登陆相关的表结构

pull/2/head
YunaiV 2021-10-03 00:35:57 +08:00
parent 9be00d6035
commit 7b3a283074
9 changed files with 226 additions and 1007 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,13 @@
package cn.iocoder.yudao.adminserver.modules.system.controller.auth; package cn.iocoder.yudao.adminserver.modules.system.controller.auth;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.*; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.*;
import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysAuthConvert; import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysAuthConvert;
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysMenuDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysMenuDO;
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO;
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.yudao.adminserver.modules.system.enums.permission.MenuTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.enums.permission.MenuTypeEnum;
import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysUserSocialTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysSocialTypeEnum;
import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysAuthService; import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysAuthService;
import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService;
import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService;
@ -22,6 +23,9 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.request.AuthRequest; import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthStateUtils; import me.zhyd.oauth.utils.AuthStateUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -107,7 +111,7 @@ public class SysAuthController {
public CommonResult<String> socialLoginRedirect(@RequestParam("type") Integer type, public CommonResult<String> socialLoginRedirect(@RequestParam("type") Integer type,
@RequestParam("redirectUri") String redirectUri) { @RequestParam("redirectUri") String redirectUri) {
// 获得对应的 AuthRequest 实现 // 获得对应的 AuthRequest 实现
AuthRequest authRequest = authRequestFactory.get(SysUserSocialTypeEnum.valueOfType(type).getSource()); AuthRequest authRequest = authRequestFactory.get(SysSocialTypeEnum.valueOfType(type).getSource());
// 生成跳转地址 // 生成跳转地址
String authorizeUri = authRequest.authorize(AuthStateUtils.createState()); String authorizeUri = authRequest.authorize(AuthStateUtils.createState());
authorizeUri = HttpUtils.replaceUrlQuery(authorizeUri, "redirect_uri", redirectUri); authorizeUri = HttpUtils.replaceUrlQuery(authorizeUri, "redirect_uri", redirectUri);
@ -132,12 +136,12 @@ public class SysAuthController {
return success(SysAuthLoginRespVO.builder().token(token).build()); return success(SysAuthLoginRespVO.builder().token(token).build());
} }
// @RequestMapping("/{type}/callback") @RequestMapping("/{type}/callback")
// public AuthResponse login(@PathVariable String type, AuthCallback callback) { public AuthResponse login(@PathVariable String type, AuthCallback callback) {
// AuthRequest authRequest = authRequestFactory.get(type); AuthRequest authRequest = authRequestFactory.get(type);
// AuthResponse<AuthUser> response = authRequest.login(callback); AuthResponse<AuthUser> response = authRequest.login(callback);
// log.info("【response】= {}", JSONUtil.toJsonStr(response)); log.info("【response】= {}", JSONUtil.toJsonStr(response));
// return response; return response;
// } }
} }

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth; package cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth;
import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysUserSocialTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysSocialTypeEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -22,7 +22,7 @@ import javax.validation.constraints.Pattern;
public class SysAuthSocialLogin2ReqVO { public class SysAuthSocialLogin2ReqVO {
@ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值")
@InEnum(SysUserSocialTypeEnum.class) @InEnum(SysSocialTypeEnum.class)
@NotNull(message = "社交平台的类型不能为空") @NotNull(message = "社交平台的类型不能为空")
private Integer type; private Integer type;

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth; package cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth;
import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysUserSocialTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysSocialTypeEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -8,11 +8,9 @@ import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
@ApiModel("社交登陆 Request VO使用 code 授权码") @ApiModel("社交登陆 Request VO使用 code 授权码")
@Data @Data
@ -22,7 +20,7 @@ import javax.validation.constraints.Pattern;
public class SysAuthSocialLoginReqVO { public class SysAuthSocialLoginReqVO {
@ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值")
@InEnum(SysUserSocialTypeEnum.class) @InEnum(SysSocialTypeEnum.class)
@NotNull(message = "社交平台的类型不能为空") @NotNull(message = "社交平台的类型不能为空")
private Integer type; private Integer type;

View File

@ -8,19 +8,20 @@ import lombok.Getter;
import java.util.Arrays; import java.util.Arrays;
/** /**
* *
* *
* @author * @author
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum SysUserSocialTypeEnum implements IntArrayValuable { public enum SysSocialTypeEnum implements IntArrayValuable {
GITEE(10, "GITEE"), // https://gitee.com/api/v5/oauth_doc#/ GITEE(10, "GITEE"), // https://gitee.com/api/v5/oauth_doc#/
DINGTALK(20, "DINGTALK"), // https://developers.dingtalk.com/document/app/obtain-identity-credentials DINGTALK(20, "DINGTALK"), // https://developers.dingtalk.com/document/app/obtain-identity-credentials
WECHAT_ENTERPRISE(30, "WECHAT_ENTERPRISE"), // https://xkcoding.com/2019/08/06/use-justauth-integration-wechat-enterprise.html
; ;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SysUserSocialTypeEnum::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SysSocialTypeEnum::getType).toArray();
/** /**
* *
@ -36,7 +37,7 @@ public enum SysUserSocialTypeEnum implements IntArrayValuable {
return ARRAYS; return ARRAYS;
} }
public static SysUserSocialTypeEnum valueOfType(Integer type) { public static SysSocialTypeEnum valueOfType(Integer type) {
return ArrayUtil.firstMatch(o -> o.getType().equals(type), values()); return ArrayUtil.firstMatch(o -> o.getType().equals(type), values());
} }

View File

@ -7,7 +7,7 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAu
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysSocialUserDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysSocialUserDO;
import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysSocialUserMapper; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysSocialUserMapper;
import cn.iocoder.yudao.adminserver.modules.system.dal.redis.auth.SysAuthSocialUserRedisDAO; import cn.iocoder.yudao.adminserver.modules.system.dal.redis.auth.SysAuthSocialUserRedisDAO;
import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysUserSocialTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysSocialTypeEnum;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
@ -256,7 +256,7 @@ public class SysAuthServiceImpl implements SysAuthService {
} }
private AuthUser obtainAuthUser(Integer type, AuthCallback authCallback) { private AuthUser obtainAuthUser(Integer type, AuthCallback authCallback) {
AuthRequest authRequest = authRequestFactory.get(SysUserSocialTypeEnum.valueOfType(type).getSource()); AuthRequest authRequest = authRequestFactory.get(SysSocialTypeEnum.valueOfType(type).getSource());
AuthResponse<?> authResponse = authRequest.login(authCallback); AuthResponse<?> authResponse = authRequest.login(authCallback);
log.info("[obtainAuthUser][请求三方平台 type({}) request({}) response({})]", type, JsonUtils.toJsonString(authCallback), log.info("[obtainAuthUser][请求三方平台 type({}) request({}) response({})]", type, JsonUtils.toJsonString(authCallback),
JsonUtils.toJsonString(authResponse)); JsonUtils.toJsonString(authResponse));

View File

@ -171,14 +171,18 @@ yudao:
justauth: justauth:
enabled: true enabled: true
type: type:
GITEE: GITEE: # Gitee
client-id: 6bb0b37a8a017e5e2dc4c34ca4756dcf80e8e392585e7035d3ede7a6db50426e client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1
client-secret: ba9f1f42e77be71f461b54da83b6f4b45a052dd7f93418f00f91f4e6934dfd1f client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9
ignore-check-redirect-uri: true ignore-check-redirect-uri: true
# redirect-uri: http://127.0.0.1:48080/api/gitee/callback DINGTALK: # 钉钉
DINGTALK:
client-id: dingvrnreaje3yqvzhxg client-id: dingvrnreaje3yqvzhxg
client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI
ignore-check-redirect-uri: true ignore-check-redirect-uri: true
WECHAT_ENTERPRISE: # 企业微信
client-id: wwd411c69a39ad2e54
client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw
agent-id: 1000004
ignore-check-redirect-uri: true
cache: cache:
type: default type: default

View File

@ -71,6 +71,11 @@ export default {
title: "钉钉", title: "钉钉",
source: "dingtalk", source: "dingtalk",
type: 20 type: 20
} , {
img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.2/wechat_enterprise.png",
title: "企业微信",
source: "wechat_enterprise",
type: 30
} }
], ],
loginRules: { loginRules: {
@ -143,8 +148,8 @@ export default {
// //
this.loading = true; this.loading = true;
// redirectUri // redirectUri
const redirectUri = location.origin + '/social-login'; // const redirectUri = location.origin + '/social-login';
// const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback'; const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback';
// const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback'; // const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback';
// //
socialLoginRedirect(provider.type, redirectUri).then((res) => { socialLoginRedirect(provider.type, redirectUri).then((res) => {

View File

@ -68,7 +68,7 @@ export default {
created() { created() {
this.getCookie(); this.getCookie();
// //
this.type = 20; this.type = 10; // TODO
this.code = this.$route.query.code; this.code = this.$route.query.code;
this.state = this.$route.query.state; this.state = this.$route.query.state;
this.$store.dispatch("SocialLogin", { this.$store.dispatch("SocialLogin", {