public class

OAuthUtil

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

Class Overview

A general container for methods related to OAuth.

Summary

Public Methods
static String encode(String stringToEncode)
Formats the input string for inclusion in a url.
static String getNonce()
Get a nonce for an OAuth request.
static String getSignatureBaseString(String requestUrl, String httpMethod, Map<String, String> baseParameters)
Calculates the signature base url as per section 9.1 of the OAuth Spec.
static String getTimestamp()
Get a timestamp for an OAuth request.
static String normalizeParameters(String requestUrl, Map<String, 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 String normalizeUrl(String requestUrl)
Calculates the normalized request url, as per section 9.1.2 of the OAuth Spec.
static Map<String, String> parseQuerystring(String queryString)
Parse a querystring into a map of key/value pairs.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static String encode (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

public static 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

public static String getSignatureBaseString (String requestUrl, String httpMethod, Map<String, String> baseParameters)

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

public static 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.

public static String normalizeParameters (String requestUrl, Map<String, 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

public static String normalizeUrl (String requestUrl)

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

public static Map<String, String> parseQuerystring (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