Search in sources :

Example 1 with HttpConfig

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;
}
Also used : UacUser(com.paascloud.provider.model.domain.UacUser) Header(org.apache.http.Header) HttpHeader(com.arronlong.httpclientutil.common.HttpHeader) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) HttpConfig(com.arronlong.httpclientutil.common.HttpConfig) LoginAuthDto(com.paascloud.base.dto.LoginAuthDto) UserTokenDto(com.paascloud.base.dto.UserTokenDto)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1 HttpConfig (com.arronlong.httpclientutil.common.HttpConfig)1 HttpHeader (com.arronlong.httpclientutil.common.HttpHeader)1 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)1 UserTokenDto (com.paascloud.base.dto.UserTokenDto)1 UacUser (com.paascloud.provider.model.domain.UacUser)1 HashMap (java.util.HashMap)1 Header (org.apache.http.Header)1