this.addGrantType = addGrantType;
}
@Override
public Token getAccessToken(final Token requestToken, final Verifier verifier) {
final OAuthRequest request = new ProxyOAuthRequest(this.api.getAccessTokenVerb(),
this.api.getAccessTokenEndpoint(), this.connectTimeout,
this.readTimeout, this.proxyHost, this.proxyPort);
if (this.getParameter) {
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, this.config.getApiKey());
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, this.config.getApiSecret());
request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, this.config.getCallback());
if (this.config.hasScope()) {
request.addQuerystringParameter(OAuthConstants.SCOPE, this.config.getScope());
}
if (this.addGrantType) {
request.addQuerystringParameter("grant_type", "authorization_code");
}
} else {
request.addBodyParameter(OAuthConstants.CLIENT_ID, this.config.getApiKey());
request.addBodyParameter(OAuthConstants.CLIENT_SECRET, this.config.getApiSecret());
request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
request.addBodyParameter(OAuthConstants.REDIRECT_URI, this.config.getCallback());
if (this.config.hasScope()) {
request.addBodyParameter(OAuthConstants.SCOPE, this.config.getScope());
}
if (this.addGrantType) {
request.addBodyParameter("grant_type", "authorization_code");
}
}
final Response response = request.send();
return this.api.getAccessTokenExtractor().extract(response.getBody());
}