Class OAuthParameters

  • All Implemented Interfaces:
    com.google.api.client.http.HttpExecuteInterceptor, com.google.api.client.http.HttpRequestInitializer

    @Beta
    public final class OAuthParameters
    extends java.lang.Object
    implements com.google.api.client.http.HttpExecuteInterceptor, com.google.api.client.http.HttpRequestInitializer
    Beta
    OAuth 1.0a parameter manager.

    The only required non-computed fields are signer and consumerKey. Use token to specify token or temporary credentials.

    Sample usage, taking advantage that this class implements HttpRequestInitializer:

      public static HttpRequestFactory createRequestFactory(HttpTransport transport) {
        OAuthParameters parameters = new OAuthParameters();
        // ...
        return transport.createRequestFactory(parameters);
      }
     

    If you have a custom request initializer, take a look at the sample usage for HttpExecuteInterceptor, which this class also implements.

    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.lang.String callback
      Absolute URI back to which the server will redirect the resource owner when the Resource Owner Authorization step is completed.
      java.lang.String consumerKey
      Required identifier portion of the client credentials (equivalent to a username).
      private static com.google.api.client.util.escape.PercentEscaper ESCAPER  
      java.lang.String nonce
      Required nonce value.
      private static java.security.SecureRandom RANDOM
      Secure random number generator to sign requests.
      java.lang.String realm
      Realm.
      java.lang.String signature
      Signature.
      java.lang.String signatureMethod
      Name of the signature method used by the client to sign the request.
      OAuthSigner signer
      Required OAuth signature algorithm.
      java.lang.String timestamp
      Required timestamp value.
      java.lang.String token
      Token value used to associate the request with the resource owner or null if the request is not associated with a resource owner.
      java.lang.String verifier
      The verification code received from the server.
      java.lang.String version
      Must either be "1.0" or null to skip.
    • Constructor Summary

      Constructors 
      Constructor Description
      OAuthParameters()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void appendParameter​(java.lang.StringBuilder buf, java.lang.String name, java.lang.String value)  
      void computeNonce()
      Computes a nonce based on the hex string of a random non-negative long, setting the value of the nonce field.
      void computeSignature​(java.lang.String requestMethod, com.google.api.client.http.GenericUrl requestUrl)
      Computes a new signature based on the fields and the given request method and URL, setting the values of the signature and signatureMethod fields.
      void computeTimestamp()
      Computes a timestamp based on the current system time, setting the value of the timestamp field.
      static java.lang.String escape​(java.lang.String value)
      Returns the escaped form of the given value using OAuth escaping rules.
      java.lang.String getAuthorizationHeader()
      Returns the Authorization header value to use with the OAuth parameter values found in the fields.
      void initialize​(com.google.api.client.http.HttpRequest request)  
      void intercept​(com.google.api.client.http.HttpRequest request)  
      private void putParameter​(java.util.TreeMap<java.lang.String,​java.lang.String> parameters, java.lang.String key, java.lang.Object value)  
      private void putParameterIfValueNotNull​(java.util.TreeMap<java.lang.String,​java.lang.String> parameters, java.lang.String key, java.lang.String value)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • RANDOM

        private static final java.security.SecureRandom RANDOM
        Secure random number generator to sign requests.
      • signer

        public OAuthSigner signer
        Required OAuth signature algorithm.
      • callback

        public java.lang.String callback
        Absolute URI back to which the server will redirect the resource owner when the Resource Owner Authorization step is completed.
      • consumerKey

        public java.lang.String consumerKey
        Required identifier portion of the client credentials (equivalent to a username).
      • nonce

        public java.lang.String nonce
        Required nonce value. Should be computed using computeNonce().
      • realm

        public java.lang.String realm
        Realm.
      • timestamp

        public java.lang.String timestamp
        Required timestamp value. Should be computed using computeTimestamp().
      • token

        public java.lang.String token
        Token value used to associate the request with the resource owner or null if the request is not associated with a resource owner.
      • verifier

        public java.lang.String verifier
        The verification code received from the server.
      • version

        public java.lang.String version
        Must either be "1.0" or null to skip. Provides the version of the authentication process as defined in this specification.
      • ESCAPER

        private static final com.google.api.client.util.escape.PercentEscaper ESCAPER
    • Constructor Detail

      • OAuthParameters

        public OAuthParameters()
    • Method Detail

      • computeNonce

        public void computeNonce()
        Computes a nonce based on the hex string of a random non-negative long, setting the value of the nonce field.
      • computeTimestamp

        public void computeTimestamp()
        Computes a timestamp based on the current system time, setting the value of the timestamp field.
      • computeSignature

        public void computeSignature​(java.lang.String requestMethod,
                                     com.google.api.client.http.GenericUrl requestUrl)
                              throws java.security.GeneralSecurityException
        Computes a new signature based on the fields and the given request method and URL, setting the values of the signature and signatureMethod fields.
        Throws:
        java.security.GeneralSecurityException - general security exception
      • getAuthorizationHeader

        public java.lang.String getAuthorizationHeader()
        Returns the Authorization header value to use with the OAuth parameter values found in the fields.
      • appendParameter

        private void appendParameter​(java.lang.StringBuilder buf,
                                     java.lang.String name,
                                     java.lang.String value)
      • putParameterIfValueNotNull

        private void putParameterIfValueNotNull​(java.util.TreeMap<java.lang.String,​java.lang.String> parameters,
                                                java.lang.String key,
                                                java.lang.String value)
      • putParameter

        private void putParameter​(java.util.TreeMap<java.lang.String,​java.lang.String> parameters,
                                  java.lang.String key,
                                  java.lang.Object value)
      • escape

        public static java.lang.String escape​(java.lang.String value)
        Returns the escaped form of the given value using OAuth escaping rules.
      • initialize

        public void initialize​(com.google.api.client.http.HttpRequest request)
                        throws java.io.IOException
        Specified by:
        initialize in interface com.google.api.client.http.HttpRequestInitializer
        Throws:
        java.io.IOException
      • intercept

        public void intercept​(com.google.api.client.http.HttpRequest request)
                       throws java.io.IOException
        Specified by:
        intercept in interface com.google.api.client.http.HttpExecuteInterceptor
        Throws:
        java.io.IOException