use of com.arronlong.httpclientutil.common.HttpConfig in project paascloud-master by paascloud.
the class UacUserTokenServiceImpl method refreshToken.
@Override
public String refreshToken(String accessToken, String refreshToken, HttpServletRequest request) throws HttpProcessException {
String token;
Map<String, Object> map = new HashMap<>(2);
map.put("grant_type", "refresh_token");
map.put("refresh_token", refreshToken);
// 插件式配置请求参数(网址、请求参数、编码、client)
Header[] headers = HttpHeader.custom().contentType(HttpHeader.Headers.APP_FORM_URLENCODED).authorization(request.getHeader(HttpHeaders.AUTHORIZATION)).build();
HttpConfig config = HttpConfig.custom().headers(headers).url(refreshTokenUrl).map(map);
token = HttpClientUtil.post(config);
JSONObject jsonObj = JSON.parseObject(token);
String accessTokenNew = (String) jsonObj.get("access_token");
String refreshTokenNew = (String) jsonObj.get("refresh_token");
String loginName = (String) jsonObj.get("loginName");
// 更新本次token数据
UserTokenDto tokenDto = this.getByAccessToken(accessToken);
tokenDto.setStatus(UacUserTokenStatusEnum.ON_REFRESH.getStatus());
UacUser uacUser = uacUserService.findUserInfoByLoginName(loginName);
LoginAuthDto loginAuthDto = new LoginAuthDto(uacUser.getId(), uacUser.getLoginName(), uacUser.getUserName(), uacUser.getGroupId(), uacUser.getGroupName());
this.updateUacUserToken(tokenDto, loginAuthDto);
// 创建刷新token
this.saveUserToken(accessTokenNew, refreshTokenNew, loginAuthDto, request);
return token;
}
Aggregations