# Google Data APIs Client Library (1.43.0)

## com.google.gdata.client.authn.oauth
Class OAuthUtil

    java.lang.Object
      com.google.gdata.client.authn.oauth.OAuthUtil

    public class OAuthUtil

extends java.lang.Object

A general container for methods related to OAuth.

Method Summary
`static java.lang.String` `encode(java.lang.String stringToEncode)` Formats the input string for inclusion in a url.
`static java.lang.String` `getNonce()` Get a nonce for an OAuth request.
`static java.lang.String` `getSignatureBaseString(java.lang.String requestUrl, java.lang.String httpMethod, java.util.Map<java.lang.String,java.lang.String> baseParameters)` Calculates the signature base url as per section 9.1 of the OAuth Spec.
`static java.lang.String` `getTimestamp()` Get a timestamp for an OAuth request.
`static java.lang.String` `normalizeParameters(java.lang.String requestUrl, java.util.Map<java.lang.String,java.lang.String> requestParameters)` Calculates the normalized request parameters string to use in the base string, as per section 9.1.1 of the OAuth Spec.
`static java.lang.String` `normalizeUrl(java.lang.String requestUrl)` Calculates the normalized request url, as per section 9.1.2 of the OAuth Spec.
`static java.util.Map<java.lang.String,java.lang.String>` `parseQuerystring(java.lang.String queryString)` Parse a querystring into a map of key/value pairs.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### getNonce

    public static java.lang.String getNonce()

  Get a nonce for an OAuth request. OAuth defines the nonce as "a random string, uniquely generated for each request. The nonce allows the Service Provider to verify that a request has never been made before and helps prevent replay attacks when requests are made over a non-secure channel (such as HTTP)."

  Returns:
    the nonce string to use in an OAuth request

### getTimestamp

    public static java.lang.String getTimestamp()

  Get a timestamp for an OAuth request. OAuth defines the timestamp as "the number of seconds since January 1, 1970 00:00:00 GMT. The timestamp value MUST be a positive integer and MUST be equal or greater than the timestamp used in previous requests."

  Returns:
    the timestamp string to use in an OAuth request.

### getSignatureBaseString

    public static java.lang.String getSignatureBaseString(java.lang.String requestUrl,
                                                          java.lang.String httpMethod,
                                                          java.util.Map<java.lang.String,java.lang.String> baseParameters)
                                                   throws OAuthException

  Calculates the signature base url as per section 9.1 of the OAuth Spec. This is a concatenation of http method, request url, and other request parameters.

  Parameters:
    `requestUrl` - the url of the request
    `httpMethod` - the http method, for example "GET" or "PUT"
    `baseParameters` - the request parameters (see section 9.1.3)
  Returns:
    the base string to be used in the OAuth signature
  Throws:
    `OAuthException` - if the input url is not formatted properly
  See Also:
    9.1 Signature Base String

### normalizeUrl

    public static java.lang.String normalizeUrl(java.lang.String requestUrl)
                                         throws OAuthException

  Calculates the normalized request url, as per section 9.1.2 of the OAuth Spec. This removes the querystring from the url and the port (if it is the standard http or https port).

  Parameters:
    `requestUrl` - the request url to normalize (not `null`)
  Returns:
    the normalized request url, as per the rules in the link above
  Throws:
    `OAuthException` - if the input url is not formatted properly
  See Also:
    9.1.2 Construct Request URL

### normalizeParameters

    public static java.lang.String normalizeParameters(java.lang.String requestUrl,
                                                       java.util.Map<java.lang.String,java.lang.String> requestParameters)

  Calculates the normalized request parameters string to use in the base string, as per section 9.1.1 of the OAuth Spec.

  Parameters:
    `requestUrl` - the request url to normalize (not `null`)
    `requestParameters` - key/value pairs of parameters in the request
  Returns:
    the parameters normalized to a string
  See Also:
    9.1.1 Normalize Request Parameters

### parseQuerystring

    public static java.util.Map<java.lang.String,java.lang.String> parseQuerystring(java.lang.String queryString)

  Parse a querystring into a map of key/value pairs.

  Parameters:
    `queryString` - the string to parse (without the '?')
  Returns:
    key/value pairs mapping to the items in the querystring

### encode

    public static java.lang.String encode(java.lang.String stringToEncode)

  Formats the input string for inclusion in a url. Account for the differences in how OAuth encodes certain characters (such as the space character).

  Parameters:
    `stringToEncode` - the string to encode
  Returns:
    the url-encoded string