From 6b147786912eeaa62350610b7ee9235ff156e3ba Mon Sep 17 00:00:00 2001 From: 三个三 <2029364173@qq.com> Date: 星期日, 02 七月 2023 15:24:14 +0800 Subject: [PATCH] !382 统一登录,授权 --- ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java | 30 ++++++++++++++++++++++++++---- 1 files changed, 26 insertions(+), 4 deletions(-) diff --git a/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java b/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java index a11520b..f24ea04 100644 --- a/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java +++ b/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java @@ -1,18 +1,38 @@ package org.dromara.common.social.utils; +import cn.hutool.core.util.ObjectUtil; import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.exception.AuthException; +import me.zhyd.oauth.model.AuthCallback; +import me.zhyd.oauth.model.AuthResponse; +import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.request.*; +import org.dromara.common.core.domain.model.LoginBody; +import org.dromara.common.social.config.properties.SocialLoginConfigProperties; +import org.dromara.common.social.config.properties.SocialProperties; /** * 璁よ瘉鎺堟潈宸ュ叿绫� * * @author thiszhc */ -public class SocialUtils { +public class SocialUtils { + public static AuthResponse<AuthUser> loginAuth(LoginBody loginBody, SocialProperties socialProperties) throws AuthException { + AuthRequest authRequest = getAuthRequest(loginBody.getSource(), socialProperties); + AuthCallback callback = new AuthCallback(); + callback.setCode(loginBody.getSocialCode()); + callback.setState(loginBody.getSocialState()); + return authRequest.login(callback); + } - public static AuthRequest getAuthRequest(String source, String clientId, - String clientSecret, String redirectUri) throws AuthException { + public static AuthRequest getAuthRequest(String source,SocialProperties socialProperties) throws AuthException { + SocialLoginConfigProperties obj = socialProperties.getType().get(source); + if (ObjectUtil.isNull(obj)) { + throw new AuthException("涓嶆敮鎸佺殑绗笁鏂圭櫥褰曠被鍨�"); + } + String clientId = obj.getClientId(); + String clientSecret = obj.getClientSecret(); + String redirectUri = obj.getRedirectUri(); AuthRequest authRequest = null; switch (source.toLowerCase()) { case "dingtalk" -> @@ -45,13 +65,15 @@ case "alipay" -> // 鏀粯瀹濆湪鍒涘缓鍥炶皟鍦板潃鏃讹紝涓嶅厑璁镐娇鐢╨ocalhost鎴栬��127.0.0.1锛屾墍浠ヨ繖鍎跨殑鍥炶皟鍦板潃浣跨敤鐨勫眬鍩熺綉鍐呯殑ip authRequest = new AuthAlipayRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) - .alipayPublicKey("").redirectUri(redirectUri).build()); + .redirectUri(redirectUri).build()); case "qq" -> authRequest = new AuthQqRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) .redirectUri(redirectUri).build()); case "wechat_open" -> authRequest = new AuthWeChatOpenRequest(AuthConfig.builder().clientId(clientId) .clientSecret(clientSecret).redirectUri(redirectUri).build()); case "csdn" -> + //娉ㄦ剰,缁忓挩璇SDN瀹樻柟瀹㈡湇寰楃煡锛孋SDN鐨勬巿鏉冨紑鏀惧钩鍙板凡缁忎笅绾裤�傚鏋滀互鍓嶇敵璇疯繃鐨勫簲鐢紝鍙互缁х画浣跨敤锛屼絾鏄笉鍐嶆敮鎸佺敵璇锋柊鐨勫簲鐢ㄣ�� + // so, 鏈」鐩腑鐨凜SDN鐧诲綍鍙兘閽堝灏戦儴鍒嗙敤鎴蜂娇鐢ㄤ簡 authRequest = new AuthCsdnRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) .redirectUri(redirectUri).build()); case "taobao" -> -- Gitblit v1.9.3