LOG.debug("Preparing to get Access Token");
LOG.debug("Given Access Token URL : " + accessTokenURL);
LOG.debug("Given Request Token : " + reqToken.toString());
if (reqToken.getKey() == null || reqToken.getKey().length() == 0) {
throw new SocialAuthException(
"Key in Request Token is null or blank");
}
Map<String, String> params = new HashMap<String, String>();
AccessGrant accessToken = null;
if (reqToken.getAttribute(OAUTH_VERIFIER) != null) {
params.put(OAUTH_VERIFIER, reqToken.getAttribute(OAUTH_VERIFIER)
.toString());
}
params.put(OAUTH_TOKEN, reqToken.getKey());
putOauthParams(params);
String reqURL = accessTokenURL;
String sig = generateSignature(config.get_signatureMethod(),
config.get_transportName(), reqURL, params, reqToken);
LOG.debug(config.get_signatureMethod()
+ " Signature for access token : " + sig);
params.put(OAUTH_SIGNATURE, sig);
String body = null;
if (MethodType.GET.toString().equals(config.get_transportName())) {
reqURL += "?" + HttpUtil.buildParams(params);
} else {
body = HttpUtil.buildParams(params);
}
LOG.debug("Access Token URL : " + reqURL);
Response response = null;
try {
response = HttpUtil.doHttpRequest(reqURL,
config.get_transportName(), body, null);
} catch (Exception e) {
LOG.debug("Error while getting Access Token");
throw new SocialAuthException("Error while getting Access Token", e);
}
if (response.getStatus() == 200) {
accessToken = new AccessGrant();
parse(response.getInputStream(), accessToken);
} else {
throw new SocialAuthException(
"Unable to retrieve the access token. Status: "
+ response.getStatus());
}
return accessToken;
}