|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ning.http.client.oauth.OAuthSignatureCalculator
public class OAuthSignatureCalculator
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.
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 |
---|
public static final String HEADER_AUTHORIZATION
protected final Random random
protected final byte[] nonceBuffer
protected final ThreadSafeHMAC mac
protected final ConsumerKey consumerAuth
protected final RequestToken userAuth
Constructor Detail |
---|
public OAuthSignatureCalculator(ConsumerKey consumerAuth, RequestToken userAuth)
consumerAuth
- Consumer key to use for signature calculationuserAuth
- Request/access token to use for signature calculationMethod Detail |
---|
public void calculateAndAddSignature(String baseURL, Request request, RequestBuilderBase<?> requestBuilder)
SignatureCalculator
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).
calculateAndAddSignature
in interface SignatureCalculator
request
- Request that is being built; needed to access content to
be signedrequestBuilder
- 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 recursionpublic String calculateSignature(String method, String baseURL, long oauthTimestamp, String nonce, FluentStringsMap formParams, FluentStringsMap queryParams)
public String constructAuthHeader(String signature, String nonce, long oauthTimestamp)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |