com.google.api.client.auth.oauth
Class OAuthParameters

java.lang.Object
  extended by com.google.api.client.auth.oauth.OAuthParameters
All Implemented Interfaces:
HttpExecuteInterceptor, HttpRequestInitializer

public final class OAuthParameters
extends Object
implements HttpExecuteInterceptor, HttpRequestInitializer

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
Author:
Yaniv Inbar

Field Summary
 String callback
          Absolute URI back to which the server will redirect the resource owner when the Resource Owner Authorization step is completed.
 String consumerKey
          Required identifier portion of the client credentials (equivalent to a username).
 String nonce
          Required nonce value.
 String realm
          Realm.
 String signature
          Signature.
 String signatureMethod
          Name of the signature method used by the client to sign the request.
 OAuthSigner signer
          Required OAuth signature algorithm.
 String timestamp
          Required timestamp value.
 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.
 String verifier
          The verification code received from the server.
 String version
          Must either be "1.0" or null to skip.
 
Constructor Summary
OAuthParameters()
           
 
Method Summary
 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(String requestMethod, 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 String escape(String value)
          Returns the escaped form of the given value using OAuth escaping rules.
 String getAuthorizationHeader()
          Returns the Authorization header value to use with the OAuth parameter values found in the fields.
 void initialize(HttpRequest request)
          Initializes a request.
 void intercept(HttpRequest request)
          Invoked at the start of HttpRequest.execute() before executing the HTTP request.
 void signRequestsUsingAuthorizationHeader(HttpTransport transport)
          Deprecated. (scheduled to be removed in 1.5) Use OAuthParameters directly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

signer

public OAuthSigner signer
Required OAuth signature algorithm.


callback

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


consumerKey

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


nonce

public String nonce
Required nonce value. Should be computed using computeNonce().


realm

public String realm
Realm.


signature

public String signature
Signature. Required but normally computed using computeSignature(java.lang.String, com.google.api.client.http.GenericUrl).


signatureMethod

public String signatureMethod
Name of the signature method used by the client to sign the request. Required, but normally computed using computeSignature(java.lang.String, com.google.api.client.http.GenericUrl).


timestamp

public String timestamp
Required timestamp value. Should be computed using computeTimestamp().


token

public 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 String verifier
The verification code received from the server.


version

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

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(String requestMethod,
                             GenericUrl requestUrl)
                      throws 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:
GeneralSecurityException - general security exception

getAuthorizationHeader

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


escape

public static String escape(String value)
Returns the escaped form of the given value using OAuth escaping rules.


signRequestsUsingAuthorizationHeader

@Deprecated
public void signRequestsUsingAuthorizationHeader(HttpTransport transport)
Deprecated. (scheduled to be removed in 1.5) Use OAuthParameters directly

Performs OAuth HTTP request signing via the Authorization header as the final HTTP request execute intercepter for the given HTTP transport.


initialize

public void initialize(HttpRequest request)
                throws IOException
Description copied from interface: HttpRequestInitializer
Initializes a request.

Specified by:
initialize in interface HttpRequestInitializer
Parameters:
request - HTTP request
Throws:
IOException

intercept

public void intercept(HttpRequest request)
               throws IOException
Description copied from interface: HttpExecuteInterceptor
Invoked at the start of HttpRequest.execute() before executing the HTTP request.

Specified by:
intercept in interface HttpExecuteInterceptor
Throws:
IOException


Copyright © 2010-2011 Google. All Rights Reserved.