com.ning.http.client.oauth
Class OAuthSignatureCalculator

java.lang.Object
  extended by com.ning.http.client.oauth.OAuthSignatureCalculator
All Implemented Interfaces:
SignatureCalculator

public class OAuthSignatureCalculator
extends Object
implements SignatureCalculator

Simple OAuth signature calculator that can used for constructing client signatures for accessing services that use OAuth for authorization.

Supports most common signature inclusion and calculation methods: HMAC-SHA1 for calculation, and Header inclusion as inclusion method. Nonce generation uses simple random numbers with base64 encoding.

Author:
tatu (tatu.saloranta@iki.fi)

Field Summary
protected  ConsumerKey consumerAuth
           
static String HEADER_AUTHORIZATION
           
protected  ThreadSafeHMAC mac
           
protected  byte[] nonceBuffer
           
protected  Random random
          To generate Nonce, need some (pseudo)randomness; no need for secure variant here.
protected  RequestToken userAuth
           
 
Constructor Summary
OAuthSignatureCalculator(ConsumerKey consumerAuth, RequestToken userAuth)
           
 
Method Summary
 void calculateAndAddSignature(String baseURL, Request request, RequestBuilderBase<?> requestBuilder)
          Method called when RequestBuilder.build() method is called.
 String calculateSignature(String method, String baseURL, long oauthTimestamp, String nonce, FluentStringsMap formParams, FluentStringsMap queryParams)
          Method for calculating OAuth signature using HMAC/SHA-1 method.
 String constructAuthHeader(String signature, String nonce, long oauthTimestamp)
          Method used for constructing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEADER_AUTHORIZATION

public static final String HEADER_AUTHORIZATION
See Also:
Constant Field Values

random

protected final Random random
To generate Nonce, need some (pseudo)randomness; no need for secure variant here.


nonceBuffer

protected final byte[] nonceBuffer

mac

protected final ThreadSafeHMAC mac

consumerAuth

protected final ConsumerKey consumerAuth

userAuth

protected final RequestToken userAuth
Constructor Detail

OAuthSignatureCalculator

public OAuthSignatureCalculator(ConsumerKey consumerAuth,
                                RequestToken userAuth)
Parameters:
consumerAuth - Consumer key to use for signature calculation
userAuth - Request/access token to use for signature calculation
Method Detail

calculateAndAddSignature

public void calculateAndAddSignature(String baseURL,
                                     Request request,
                                     RequestBuilderBase<?> requestBuilder)
Description copied from interface: SignatureCalculator
Method called when RequestBuilder.build() method is called. Should first calculate signature information and then modify request (using passed RequestBuilder) to add signature (usually as an HTTP header).

Specified by:
calculateAndAddSignature in interface SignatureCalculator
request - Request that is being built; needed to access content to be signed
requestBuilder - builder that can be used to modify request, usually by adding header that includes calculated signature. Be sure NOT to call RequestBuilder.build() since this will cause infinite recursion

calculateSignature

public String calculateSignature(String method,
                                 String baseURL,
                                 long oauthTimestamp,
                                 String nonce,
                                 FluentStringsMap formParams,
                                 FluentStringsMap queryParams)
Method for calculating OAuth signature using HMAC/SHA-1 method.


constructAuthHeader

public String constructAuthHeader(String signature,
                                  String nonce,
                                  long oauthTimestamp)
Method used for constructing



Copyright © 2011. All Rights Reserved.