Interface OAuthConsumer

  • All Superinterfaces:
    java.io.Serializable
    All Known Implementing Classes:
    AbstractOAuthConsumer, CommonsHttpOAuthConsumer, DefaultOAuthConsumer

    public interface OAuthConsumer
    extends java.io.Serializable

    Exposes a simple interface to sign HTTP requests using a given OAuth token and secret. Refer to OAuthProvider how to retrieve a valid token and token secret.

    HTTP messages are signed as follows:

     // exchange the arguments with the actual token/secret pair
     OAuthConsumer consumer = new DefaultOAuthConsumer("1234", "5678");
     
     URL url = new URL("http://example.com/protected.xml");
     HttpURLConnection request = (HttpURLConnection) url.openConnection();
     
     consumer.sign(request);
     
     request.connect();
     

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.String getConsumerKey()  
      java.lang.String getConsumerSecret()  
      HttpParameters getRequestParameters()
      Returns all parameters collected from the HTTP request during message signing (this means the return value may be NULL before a call to sign(oauth.signpost.http.HttpRequest)), plus all required OAuth parameters that were added because the request didn't contain them beforehand.
      java.lang.String getToken()  
      java.lang.String getTokenSecret()  
      void setAdditionalParameters​(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.
      void setMessageSigner​(OAuthMessageSigner messageSigner)
      Sets the message signer that should be used to generate the OAuth signature.
      void setSendEmptyTokens​(boolean enable)
      Causes the consumer to always include the oauth_token parameter to be sent, even if blank.
      void setSigningStrategy​(SigningStrategy signingStrategy)
      Defines which strategy should be used to write a signature to an HTTP request.
      void setTokenWithSecret​(java.lang.String token, java.lang.String tokenSecret)
      Sets the OAuth token and token secret used for message signing.
      HttpRequest sign​(java.lang.Object request)
      Signs the given HTTP request by writing an OAuth signature (and other required OAuth parameters) to it.
      java.lang.String sign​(java.lang.String url)
      "Signs" the given URL by appending all OAuth parameters to it which are required for message signing.
      HttpRequest sign​(HttpRequest request)
      Signs the given HTTP request by writing an OAuth signature (and other required OAuth parameters) to it.
    • Method Detail

      • setAdditionalParameters

        void setAdditionalParameters​(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. you don't have to put them into the request first. The consumer's SigningStrategy will 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.
        Parameters:
        additionalParameters - the parameters
      • setTokenWithSecret

        void setTokenWithSecret​(java.lang.String token,
                                java.lang.String tokenSecret)
        Sets the OAuth token and token secret used for message signing.
        Parameters:
        token - the token
        tokenSecret - the token secret
      • getToken

        java.lang.String getToken()
      • getTokenSecret

        java.lang.String getTokenSecret()
      • getConsumerKey

        java.lang.String getConsumerKey()
      • getConsumerSecret

        java.lang.String getConsumerSecret()
      • getRequestParameters

        HttpParameters getRequestParameters()
        Returns all parameters collected from the HTTP request during message signing (this means the return value may be NULL before a call to sign(oauth.signpost.http.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.
        Returns:
        the request parameters used for message signing