From 6b147786912eeaa62350610b7ee9235ff156e3ba Mon Sep 17 00:00:00 2001 From: 三个三 <2029364173@qq.com> Date: 星期日, 02 七月 2023 15:24:14 +0800 Subject: [PATCH] !382 统一登录,授权 --- ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java | 36 +++++++++++++++--------------------- 1 files changed, 15 insertions(+), 21 deletions(-) diff --git a/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java b/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java index 9032d27..2ed4ed4 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java @@ -6,7 +6,6 @@ import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; 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; @@ -87,7 +86,7 @@ } /** - * 璁よ瘉鎺堟潈 + * 绗笁鏂圭櫥褰曡姹� * * @param source 鐧诲綍鏉ユ簮 * @return 缁撴灉 @@ -98,36 +97,31 @@ if (ObjectUtil.isNull(obj)) { return R.fail(source + "骞冲彴璐﹀彿鏆備笉鏀寔"); } - AuthRequest authRequest = SocialUtils.getAuthRequest(source, - obj.getClientId(), - obj.getClientSecret(), - obj.getRedirectUri()); + AuthRequest authRequest = SocialUtils.getAuthRequest(source, socialProperties); String authorizeUrl = authRequest.authorize(AuthStateUtils.createState()); return R.ok(authorizeUrl); } /** * 绗笁鏂圭櫥褰曞洖璋冧笟鍔″鐞� - * - * @param source 鐧诲綍鏉ユ簮 - * @param callback 鎺堟潈鍝嶅簲瀹炰綋 + * 缁戝畾鎺堟潈 + * @param loginBody * @return 缁撴灉 */ @SuppressWarnings("unchecked") - @GetMapping("/social-login") - public R<String> socialLogin(String source, AuthCallback callback) { - SocialLoginConfigProperties obj = socialProperties.getType().get(source); - if (ObjectUtil.isNull(obj)) { - return R.fail(source + "骞冲彴璐﹀彿鏆備笉鏀寔"); - } - AuthRequest authRequest = SocialUtils.getAuthRequest(source, - obj.getClientId(), - obj.getClientSecret(), - obj.getRedirectUri()); - AuthResponse<AuthUser> response = authRequest.login(callback); - return loginService.socialLogin(source, response); + @PostMapping("/social/callback") + public R<LoginVo> socialLogin(@RequestBody LoginBody loginBody) { + // 鑾峰彇绗笁鏂圭櫥褰曚俊鎭� + AuthResponse<AuthUser> response = SocialUtils.loginAuth(loginBody, socialProperties); + AuthUser authUserData = response.getData(); + // 鍒ゆ柇鎺堟潈鍝嶅簲鏄惁鎴愬姛 + if (!response.ok()) { + return R.fail(response.getMsg()); + } + return loginService.sociaRegister(authUserData); } + /** * 鍙栨秷鎺堟潈 * -- Gitblit v1.9.3