Java Reference
In-Depth Information
implements HttpExecuteInterceptor, HttpRequestInitializer {
/*
* Due to a limitation in OAuthParameters, form parameters (as those
* used by POST requests) are not included in the construction of the
* OAuth signature. As such, we build a new class based on the source
* code of OAuthParameters to work around this issue.
*
* Note that, normally, we would write a superclass which extends
* OAuthParameters, but since OAuthParameters is declared as a final
* class, we cannot do so here.
*/
private static final SecureRandom RANDOM = new SecureRandom();
public OAuthSigner signer;
public String callback;
public String consumerKey;
public String nonce;
public String realm;
public String signature;
public String signatureMethod;
public String timestamp;
public String token;
public String verifier;
public String version;
private static final PercentEscaper ESCAPER =
new PercentEscaper("-_.~", false);
public void computeNonce() {
nonce = Long.toHexString(Math.abs(RANDOM.nextLong()));
}
public void computeTimestamp() {
timestamp = Long.toString(System.currentTimeMillis() / 1000);
}
public void computeSignature(String requestMethod, GenericUrl requestUrl,
HttpContent httpContent)
throws GeneralSecurityException {
OAuthSigner signer = this.signer;
String signatureMethod = this.signatureMethod = signer.getSignatureMethod();
TreeMap<String, String> parameters = new TreeMap<String, String>();
// Include all OAuth values in the signature
putParameterIfValueNotNull(parameters, "oauth_callback", callback);
putParameterIfValueNotNull(parameters, "oauth_consumer_key", consumerKey);
putParameterIfValueNotNull(parameters, "oauth_nonce", nonce);
putParameterIfValueNotNull(parameters, "oauth_signature_method",
signatureMethod);
putParameterIfValueNotNull(parameters, "oauth_timestamp", timestamp);
putParameterIfValueNotNull(parameters, "oauth_token", token);
putParameterIfValueNotNull(parameters, "oauth_verifier", verifier);
putParameterIfValueNotNull(parameters, "oauth_version", version);
Search WWH ::




Custom Search