use of com.qasymphony.ci.plugin.exception.OAuthException in project jenkin-qtest-plugin by QASymphony.
the class OauthProvider method getAccessToken.
public static String getAccessToken(String url, String apiKey, String secretKey) throws OAuthException {
StringBuilder sb = new StringBuilder().append(url).append("/oauth/token?grant_type=refresh_token").append("&refresh_token=").append(HttpClientUtils.encode(apiKey));
Map<String, String> headers = new HashMap<>();
headers.put(Constants.HEADER_AUTH, secretKey);
try {
ResponseEntity entity = HttpClientUtils.post(sb.toString(), headers, null);
if (HttpStatus.SC_OK != entity.getStatusCode()) {
throw new OAuthException(entity.getBody(), entity.getStatusCode());
}
JsonNode node = JsonUtils.readTree(entity.getBody());
if (null == node) {
throw new OAuthException("Cannot get access token from: " + entity.getBody(), entity.getStatusCode());
}
return JsonUtils.getText(node, "access_token");
} catch (Exception e) {
throw new OAuthException(e.getMessage(), e);
}
}
Aggregations