mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-03-12 01:30:08 +08:00
!382 统一登录,授权
This commit is contained in:
@@ -6,7 +6,6 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
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 @@ public class AuthController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证授权
|
||||
* 第三方登录请求
|
||||
*
|
||||
* @param source 登录来源
|
||||
* @return 结果
|
||||
@@ -98,36 +97,31 @@ public class AuthController {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消授权
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user