Class AbstractOAuthConsumer
- All Implemented Interfaces:
Serializable, OAuthConsumer
- Direct Known Subclasses:
CommonsHttpOAuthConsumer, DefaultOAuthConsumer
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate HttpParametersprivate Stringprivate Stringprivate OAuthMessageSignerprivate final Randomprivate HttpParametersprivate booleanprivate static final longprivate SigningStrategyprivate String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcollectBodyParameters(HttpRequest request, HttpParameters out) Collects x-www-form-urlencoded body parameters as per OAuth Core 1.0 spec section 9.1.1protected voidcollectHeaderParameters(HttpRequest request, HttpParameters out) Collects OAuth Authorization header parameters as per OAuth Core 1.0 spec section 9.1.1protected voidcollectQueryParameters(HttpRequest request, HttpParameters out) Collects HTTP GET query string parameters as per OAuth Core 1.0 spec section 9.1.1protected voidHelper method that adds any OAuth parameters to the given request parameters which are missing from the current request but required for signing.protected Stringprotected StringReturns all parameters collected from the HTTP request during message signing (this means the return value may be NULL before a call toOAuthConsumer.sign(HttpRequest)), plus all required OAuth parameters that were added because the request didn't contain them beforehand.getToken()voidsetAdditionalParameters(HttpParameters additionalParameters) Allows you to add parameters (typically OAuth parameters such as oauth_callback or oauth_verifier) which will go directly into the signer, i.e.voidsetMessageSigner(OAuthMessageSigner messageSigner) Sets the message signer that should be used to generate the OAuth signature.voidsetSendEmptyTokens(boolean enable) Causes the consumer to always include the oauth_token parameter to be sent, even if blank.voidsetSigningStrategy(SigningStrategy signingStrategy) Defines which strategy should be used to write a signature to an HTTP request.voidsetTokenWithSecret(String token, String tokenSecret) Sets the OAuth token and token secret used for message signing.Signs the given HTTP request by writing an OAuth signature (and other required OAuth parameters) to it."Signs" the given URL by appending all OAuth parameters to it which are required for message signing.sign(HttpRequest request) Signs the given HTTP request by writing an OAuth signature (and other required OAuth parameters) to it.protected abstract HttpRequestAdapts the given request object to a SignpostHttpRequest.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
consumerKey
-
consumerSecret
-
token
-
messageSigner
-
signingStrategy
-
additionalParameters
-
requestParameters
-
sendEmptyTokens
private boolean sendEmptyTokens -
random
-
-
Constructor Details
-
AbstractOAuthConsumer
-
-
Method Details
-
setMessageSigner
Description copied from interface:OAuthConsumerSets the message signer that should be used to generate the OAuth signature.- Specified by:
setMessageSignerin interfaceOAuthConsumer- Parameters:
messageSigner- the signer- See Also:
-
setSigningStrategy
Description copied from interface:OAuthConsumerDefines which strategy should be used to write a signature to an HTTP request.- Specified by:
setSigningStrategyin interfaceOAuthConsumer- Parameters:
signingStrategy- the strategy- See Also:
-
setAdditionalParameters
Description copied from interface:OAuthConsumerAllows you to add parameters (typically OAuth parameters such as oauth_callback or oauth_verifier) which will go directly into the signer, i.e. you don't have to put them into the request first. The consumer'sSigningStrategywill then take care of writing them to the correct part of the request before it is sent. This is useful if you want to pre-set custom OAuth parameters. Note that these parameters are expected to already be percent encoded -- they will be simply merged as-is. BE CAREFUL WITH THIS METHOD! Your service provider may decide to ignore any non-standard OAuth params when computing the signature.- Specified by:
setAdditionalParametersin interfaceOAuthConsumer- Parameters:
additionalParameters- the parameters
-
sign
public HttpRequest sign(HttpRequest request) throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException Description copied from interface:OAuthConsumerSigns the given HTTP request by writing an OAuth signature (and other required OAuth parameters) to it. Where these parameters are written depends on the currentSigningStrategy.- Specified by:
signin interfaceOAuthConsumer- Parameters:
request- the request to sign- Returns:
- the request object passed as an argument
- Throws:
OAuthMessageSignerExceptionOAuthExpectationFailedExceptionOAuthCommunicationException
-
sign
public HttpRequest sign(Object request) throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException Description copied from interface:OAuthConsumerSigns the given HTTP request by writing an OAuth signature (and other required OAuth parameters) to it. Where these parameters are written depends on the current
This method accepts HTTP library specific request objects; the consumer implementation must ensure that only those request types are passed which it supports.SigningStrategy.- Specified by:
signin interfaceOAuthConsumer- Parameters:
request- the request to sign- Returns:
- the request object passed as an argument
- Throws:
OAuthMessageSignerExceptionOAuthExpectationFailedExceptionOAuthCommunicationException
-
sign
public String sign(String url) throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException Description copied from interface:OAuthConsumer"Signs" the given URL by appending all OAuth parameters to it which are required for message signing. The assumed HTTP method is GET. Essentially, this is equivalent to signing an HTTP GET request, but it can be useful if your application requires clickable links to protected resources, i.e. when your application does not have access to the actual request that is being sent.
- Specified by:
signin interfaceOAuthConsumer- Parameters:
url- the input URL. May have query parameters.- Returns:
- the input URL, with all necessary OAuth parameters attached as a query string. Existing query parameters are preserved.
- Throws:
OAuthMessageSignerExceptionOAuthExpectationFailedExceptionOAuthCommunicationException
-
wrap
Adapts the given request object to a SignpostHttpRequest. How this is done depends on the consumer implementation.- Parameters:
request- the native HTTP request instance- Returns:
- the adapted request
-
setTokenWithSecret
Description copied from interface:OAuthConsumerSets the OAuth token and token secret used for message signing.- Specified by:
setTokenWithSecretin interfaceOAuthConsumer- Parameters:
token- the tokentokenSecret- the token secret
-
getToken
- Specified by:
getTokenin interfaceOAuthConsumer
-
getTokenSecret
- Specified by:
getTokenSecretin interfaceOAuthConsumer
-
getConsumerKey
- Specified by:
getConsumerKeyin interfaceOAuthConsumer
-
getConsumerSecret
- Specified by:
getConsumerSecretin interfaceOAuthConsumer
-
completeOAuthParameters
Helper method that adds any OAuth parameters to the given request parameters which are missing from the current request but required for signing. A good example is the oauth_nonce parameter, which is typically not provided by the client in advance.
It's probably not a very good idea to override this method. If you want to generate different nonces or timestamps, override
generateNonce()orgenerateTimestamp()instead.- Parameters:
out- the request parameter which should be completed
-
getRequestParameters
Description copied from interface:OAuthConsumerReturns all parameters collected from the HTTP request during message signing (this means the return value may be NULL before a call toOAuthConsumer.sign(HttpRequest)), plus all required OAuth parameters that were added because the request didn't contain them beforehand. In other words, this is the exact set of parameters that were used for creating the message signature.- Specified by:
getRequestParametersin interfaceOAuthConsumer- Returns:
- the request parameters used for message signing
-
setSendEmptyTokens
public void setSendEmptyTokens(boolean enable) Description copied from interface:OAuthConsumerCauses the consumer to always include the oauth_token parameter to be sent, even if blank. If you're seeing 401s during calls to
OAuthProvider.retrieveRequestToken(OAuthConsumer, String, String...), try setting this to true.- Specified by:
setSendEmptyTokensin interfaceOAuthConsumer- Parameters:
enable- true or false
-
collectHeaderParameters
Collects OAuth Authorization header parameters as per OAuth Core 1.0 spec section 9.1.1 -
collectBodyParameters
Collects x-www-form-urlencoded body parameters as per OAuth Core 1.0 spec section 9.1.1- Throws:
IOException
-
collectQueryParameters
Collects HTTP GET query string parameters as per OAuth Core 1.0 spec section 9.1.1 -
generateTimestamp
-
generateNonce
-