| | |
| | | import me.zhyd.oauth.model.AuthUser; |
| | | import me.zhyd.oauth.request.AuthRequest; |
| | | import me.zhyd.oauth.utils.AuthStateUtils; |
| | | import org.dromara.common.core.constant.UserConstants; |
| | | import org.dromara.common.core.domain.R; |
| | | import org.dromara.common.core.domain.model.LoginBody; |
| | | import org.dromara.common.core.domain.model.RegisterBody; |
| | |
| | | if (ObjectUtil.isNull(client) || !StringUtils.contains(client.getGrantType(), grantType)) { |
| | | log.info("客户端id: {} 认证类型:{} 异常!.", clientId, grantType); |
| | | return R.fail(MessageUtils.message("auth.grant.type.error")); |
| | | } else if (!UserConstants.NORMAL.equals(client.getStatus())) { |
| | | return R.fail(MessageUtils.message("auth.grant.type.stop")); |
| | | } |
| | | // 校验租户 |
| | | loginService.checkTenant(loginBody.getTenantId()); |
| | |
| | | } |
| | | AuthRequest authRequest = SocialUtils.getAuthRequest(source, socialProperties); |
| | | String authorizeUrl = authRequest.authorize(AuthStateUtils.createState()); |
| | | return R.ok(authorizeUrl); |
| | | return R.ok("操作成功", authorizeUrl); |
| | | } |
| | | |
| | | /** |
| | | * 第三方登录回调业务处理 |
| | | * 绑定授权 |
| | | * @param loginBody |
| | | * 第三方登录回调业务处理 绑定授权 |
| | | * |
| | | * @param loginBody 请求体 |
| | | * @return 结果 |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | @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); |
| | | public R<Void> socialCallback(@RequestBody LoginBody loginBody) { |
| | | // 获取第三方登录信息 |
| | | AuthResponse<AuthUser> response = SocialUtils.loginAuth(loginBody, socialProperties); |
| | | AuthUser authUserData = response.getData(); |
| | | // 判断授权响应是否成功 |
| | | if (!response.ok()) { |
| | | return R.fail(response.getMsg()); |
| | | } |
| | | loginService.socialRegister(authUserData); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |