fix(iam): 单点登录问题修复
This commit is contained in:
+4
-32
@@ -2,8 +2,6 @@ package com.jero.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -244,55 +242,29 @@ public class LoginServiceImpl implements ILoginService {
|
||||
|
||||
private OauthUserInfo getUserInfo(Oauth oauth, OauthAccessToken oauthAccessToken) {
|
||||
String userInfoUrl = oauth.getUserInfoUrl() + "?access_token=" + oauthAccessToken.getAccessToken() + "&client_id=" + oauth.getClientId();
|
||||
/**
|
||||
* 如果返回json
|
||||
* OauthUserInfo oauthUserInfo = restTemplate.getForObject(userInfoUrl, OauthUserInfo.class);
|
||||
*/
|
||||
|
||||
// 返回String --> jsonString --> jsonObject --> 实体
|
||||
String resultStr = restTemplate.getForObject(userInfoUrl, String.class);
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(resultStr));
|
||||
OauthUserInfo oauthUserInfo = JSON.toJavaObject(jsonObject, OauthUserInfo.class);
|
||||
|
||||
OauthUserInfo oauthUserInfo = restTemplate.getForObject(userInfoUrl, OauthUserInfo.class);
|
||||
if (Objects.isNull(oauthUserInfo) || Objects.isNull(oauthUserInfo.getSpRoleList()) || oauthUserInfo.getSpRoleList().isEmpty()){
|
||||
throw new JeroBootException("获取用户信息返回信息为空!");
|
||||
}
|
||||
if (StringUtils.isBlank(oauthUserInfo.getErrCode())){
|
||||
if (StringUtils.isNotBlank(oauthUserInfo.getErrCode())){
|
||||
throw new JeroBootException(oauthUserInfo.getMsg());
|
||||
}
|
||||
return oauthUserInfo;
|
||||
}
|
||||
|
||||
private OauthAccessToken getAccessToken(Oauth oauth) {
|
||||
/**
|
||||
// 1.表单提交方式
|
||||
// 设置为表单提交,按需求加
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Content-Type","application/x-www-form-urlencoded");
|
||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
// 组装请求信息
|
||||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
||||
params.add("client_id", oauth.getClientId());
|
||||
params.add("client_secret", oauth.getClientSecret());
|
||||
params.add("grant_type", oauth.getGrantType());
|
||||
params.add("redirect_uri", oauth.getRedirectUri());
|
||||
params.add("code", oauth.getCode());
|
||||
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers);
|
||||
OauthAccessToken oauthAccessToken = restTemplate.postForObject(oauth.getAccessTokenUrl(), requestEntity, OauthAccessToken.class);
|
||||
*/
|
||||
|
||||
// 2.params传参
|
||||
String accessTokenUrl = oauth.getAccessTokenUrl();
|
||||
// 拼接参数
|
||||
accessTokenUrl = accessTokenUrl + "?client_id=" + oauth.getClientId()
|
||||
+ "&grant_type=" + oauth.getGrantType()
|
||||
+ "&code=" + oauth.getCode()
|
||||
+ "&client_secret" + oauth.getClientSecret();
|
||||
+ "&client_secret=" + oauth.getClientSecret();
|
||||
OauthAccessToken oauthAccessToken = restTemplate.postForObject(accessTokenUrl, null, OauthAccessToken.class);
|
||||
if (Objects.isNull(oauthAccessToken) || StringUtils.isBlank(oauthAccessToken.getAccessToken())){
|
||||
throw new JeroBootException("获取AccessToken返回信息为空!");
|
||||
}
|
||||
if (StringUtils.isBlank(oauthAccessToken.getErrCode())){
|
||||
if (StringUtils.isNotBlank(oauthAccessToken.getErrCode())){
|
||||
throw new JeroBootException(oauthAccessToken.getMsg());
|
||||
}
|
||||
return oauthAccessToken;
|
||||
|
||||
Reference in New Issue
Block a user