mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	增加三方登陆相关的表结构
This commit is contained in:
		| @@ -1,12 +1,13 @@ | ||||
| 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.convert.auth.SysAuthConvert; | ||||
| 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.user.SysUserDO; | ||||
| 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.permission.SysPermissionService; | ||||
| 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.ApiOperation; | ||||
| 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.utils.AuthStateUtils; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| @@ -107,7 +111,7 @@ public class SysAuthController { | ||||
|     public CommonResult<String> socialLoginRedirect(@RequestParam("type") Integer type, | ||||
|                                                     @RequestParam("redirectUri") String redirectUri) { | ||||
|         // 获得对应的 AuthRequest 实现 | ||||
|         AuthRequest authRequest = authRequestFactory.get(SysUserSocialTypeEnum.valueOfType(type).getSource()); | ||||
|         AuthRequest authRequest = authRequestFactory.get(SysSocialTypeEnum.valueOfType(type).getSource()); | ||||
|         // 生成跳转地址 | ||||
|         String authorizeUri = authRequest.authorize(AuthStateUtils.createState()); | ||||
|         authorizeUri = HttpUtils.replaceUrlQuery(authorizeUri, "redirect_uri", redirectUri); | ||||
| @@ -132,12 +136,12 @@ public class SysAuthController { | ||||
|         return success(SysAuthLoginRespVO.builder().token(token).build()); | ||||
|     } | ||||
|  | ||||
| //    @RequestMapping("/{type}/callback") | ||||
| //    public AuthResponse login(@PathVariable String type, AuthCallback callback) { | ||||
| //        AuthRequest authRequest = authRequestFactory.get(type); | ||||
| //        AuthResponse<AuthUser> response = authRequest.login(callback); | ||||
| //        log.info("【response】= {}", JSONUtil.toJsonStr(response)); | ||||
| //        return response; | ||||
| //    } | ||||
|     @RequestMapping("/{type}/callback") | ||||
|     public AuthResponse login(@PathVariable String type, AuthCallback callback) { | ||||
|         AuthRequest authRequest = authRequestFactory.get(type); | ||||
|         AuthResponse<AuthUser> response = authRequest.login(callback); | ||||
|         log.info("【response】= {}", JSONUtil.toJsonStr(response)); | ||||
|         return response; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| 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 io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| @@ -22,7 +22,7 @@ import javax.validation.constraints.Pattern; | ||||
| public class SysAuthSocialLogin2ReqVO { | ||||
|  | ||||
|     @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") | ||||
|     @InEnum(SysUserSocialTypeEnum.class) | ||||
|     @InEnum(SysSocialTypeEnum.class) | ||||
|     @NotNull(message = "社交平台的类型不能为空") | ||||
|     private Integer type; | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| 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 io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| @@ -8,11 +8,9 @@ import lombok.AllArgsConstructor; | ||||
| import lombok.Builder; | ||||
| import lombok.Data; | ||||
| import lombok.NoArgsConstructor; | ||||
| import org.hibernate.validator.constraints.Length; | ||||
|  | ||||
| import javax.validation.constraints.NotEmpty; | ||||
| import javax.validation.constraints.NotNull; | ||||
| import javax.validation.constraints.Pattern; | ||||
|  | ||||
| @ApiModel("社交登陆 Request VO,使用 code 授权码") | ||||
| @Data | ||||
| @@ -22,7 +20,7 @@ import javax.validation.constraints.Pattern; | ||||
| public class SysAuthSocialLoginReqVO { | ||||
|  | ||||
|     @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") | ||||
|     @InEnum(SysUserSocialTypeEnum.class) | ||||
|     @InEnum(SysSocialTypeEnum.class) | ||||
|     @NotNull(message = "社交平台的类型不能为空") | ||||
|     private Integer type; | ||||
|  | ||||
|   | ||||
| @@ -8,19 +8,20 @@ import lombok.Getter; | ||||
| import java.util.Arrays; | ||||
| 
 | ||||
| /** | ||||
|  * 用户的社交平台的类型枚举 | ||||
|  * 社交用户的类型枚举 | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @Getter | ||||
| @AllArgsConstructor | ||||
| public enum SysUserSocialTypeEnum implements IntArrayValuable { | ||||
| public enum SysSocialTypeEnum implements IntArrayValuable { | ||||
| 
 | ||||
|     GITEE(10, "GITEE"), // https://gitee.com/api/v5/oauth_doc#/ | ||||
|     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; | ||||
|     } | ||||
| 
 | ||||
|     public static SysUserSocialTypeEnum valueOfType(Integer type) { | ||||
|     public static SysSocialTypeEnum valueOfType(Integer type) { | ||||
|         return ArrayUtil.firstMatch(o -> o.getType().equals(type), values()); | ||||
|     } | ||||
| 
 | ||||
| @@ -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.mysql.user.SysSocialUserMapper; | ||||
| 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.UserTypeEnum; | ||||
| 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) { | ||||
|         AuthRequest authRequest = authRequestFactory.get(SysUserSocialTypeEnum.valueOfType(type).getSource()); | ||||
|         AuthRequest authRequest = authRequestFactory.get(SysSocialTypeEnum.valueOfType(type).getSource()); | ||||
|         AuthResponse<?> authResponse = authRequest.login(authCallback); | ||||
|         log.info("[obtainAuthUser][请求三方平台 type({}) request({}) response({})]", type, JsonUtils.toJsonString(authCallback), | ||||
|                 JsonUtils.toJsonString(authResponse)); | ||||
|   | ||||
| @@ -171,14 +171,18 @@ yudao: | ||||
| justauth: | ||||
|   enabled: true | ||||
|   type: | ||||
|     GITEE: | ||||
|       client-id: 6bb0b37a8a017e5e2dc4c34ca4756dcf80e8e392585e7035d3ede7a6db50426e | ||||
|       client-secret: ba9f1f42e77be71f461b54da83b6f4b45a052dd7f93418f00f91f4e6934dfd1f | ||||
|     GITEE: # Gitee | ||||
|       client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1 | ||||
|       client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9 | ||||
|       ignore-check-redirect-uri: true | ||||
| #      redirect-uri: http://127.0.0.1:48080/api/gitee/callback | ||||
|     DINGTALK: | ||||
|     DINGTALK: # 钉钉 | ||||
|       client-id: dingvrnreaje3yqvzhxg | ||||
|       client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI | ||||
|       ignore-check-redirect-uri: true | ||||
|     WECHAT_ENTERPRISE: # 企业微信 | ||||
|       client-id: wwd411c69a39ad2e54 | ||||
|       client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw | ||||
|       agent-id: 1000004 | ||||
|       ignore-check-redirect-uri: true | ||||
|   cache: | ||||
|     type: default | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV