com.fitbit.api.client.http
Class OAuth

java.lang.Object
  extended by com.fitbit.api.client.http.OAuth
All Implemented Interfaces:
Serializable

public class OAuth
extends Object
implements Serializable

Author:
Yusuke Yamamoto - yusuke at mac.com
See Also:
OAuth Core 1.0, Serialized Form

Constructor Summary
OAuth(String consumerKey, String consumerSecret)
           
 
Method Summary
static String constructRequestURL(String url)
          The Signature Base String includes the request absolute URL, tying the signature to a specific endpoint.
static String encode(String value)
           
static String encodeParameters(List<PostParameter> postParams)
           
static String encodeParameters(List<PostParameter> postParams, String splitter, boolean quot)
           
 boolean equals(Object o)
           
 String generateSignature(String data)
           
 String generateSignature(String data, com.fitbit.api.client.http.OAuthToken token)
          Computes RFC 2104-compliant HMAC signature.
 int hashCode()
           
static String normalizeAuthorizationHeaders(List<PostParameter> params)
           
static String normalizeRequestParameters(List<PostParameter> params)
           
static String normalizeRequestParameters(PostParameter[] params)
          The request parameters are collected, sorted and concatenated into a normalized string:
• Parameters in the OAuth HTTP Authorization header excluding the realm parameter.
• Parameters in the HTTP POST request body (with a content-type of application/x-www-form-urlencoded).
• HTTP GET parameters added to the URLs in the query part (as defined by [RFC3986] section 3).

The oauth_signature parameter MUST be excluded.
The parameters are normalized into a single string as follows:
1.
 void setConsumerKey(String consumerKey)
           
 void setConsumerSecret(String consumerSecret)
           
static List<PostParameter> toParamList(PostParameter[] params)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OAuth

public OAuth(String consumerKey,
             String consumerSecret)
Method Detail

generateSignature

public String generateSignature(String data,
                                com.fitbit.api.client.http.OAuthToken token)
Computes RFC 2104-compliant HMAC signature.

Parameters:
data - the data to be signed
Returns:
signature
See Also:
OAuth Core - 9.2.1. Generating Signature

generateSignature

public String generateSignature(String data)

normalizeRequestParameters

public static String normalizeRequestParameters(PostParameter[] params)
The request parameters are collected, sorted and concatenated into a normalized string:
• Parameters in the OAuth HTTP Authorization header excluding the realm parameter.
• Parameters in the HTTP POST request body (with a content-type of application/x-www-form-urlencoded).
• HTTP GET parameters added to the URLs in the query part (as defined by [RFC3986] section 3).

The oauth_signature parameter MUST be excluded.
The parameters are normalized into a single string as follows:
1. Parameters are sorted by name, using lexicographical byte value ordering. If two or more parameters share the same name, they are sorted by their value. For example:
2. a=1, c=hi%20there, f=25, f=50, f=a, z=p, z=t
3.
4. Parameters are concatenated in their sorted order into a single string. For each parameter, the name is separated from the corresponding value by an ‘=’ character (ASCII code 61), even if the value is empty. Each name-value pair is separated by an ‘&’ character (ASCII code 38). For example:
5. a=1&c=hi%20there&f=25&f=50&f=a&z=p&z=t
6.

Parameters:
params - parameters to be normalized and concatenated
Returns:
nomarized and concatenated parameters
See Also:
OAuth Core - 9.1.1. Normalize Request Parameters

normalizeRequestParameters

public static String normalizeRequestParameters(List<PostParameter> params)

normalizeAuthorizationHeaders

public static String normalizeAuthorizationHeaders(List<PostParameter> params)

toParamList

public static List<PostParameter> toParamList(PostParameter[] params)

encodeParameters

public static String encodeParameters(List<PostParameter> postParams)
Parameters:
postParams - parameters to be enocded and concatenated
Returns:
eoncoded string
See Also:
OAuth / TestCases, Space encoding - OAuth | Google Groups

encodeParameters

public static String encodeParameters(List<PostParameter> postParams,
                                      String splitter,
                                      boolean quot)

encode

public static String encode(String value)
Parameters:
value - string to be encoded
Returns:
encoded string
See Also:
OAuth / TestCases, Space encoding - OAuth | Google Groups, RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax - 2.1. Percent-Encoding

constructRequestURL

public static String constructRequestURL(String url)
The Signature Base String includes the request absolute URL, tying the signature to a specific endpoint. The URL used in the Signature Base String MUST include the scheme, authority, and path, and MUST exclude the query and fragment as defined by [RFC3986] section 3.
If the absolute request URL is not available to the Service Provider (it is always available to the Consumer), it can be constructed by combining the scheme being used, the HTTP Host header, and the relative HTTP request URL. If the Host header is not available, the Service Provider SHOULD use the host name communicated to the Consumer in the documentation or other means.
The Service Provider SHOULD document the form of URL used in the Signature Base String to avoid ambiguity due to URL normalization. Unless specified, URL scheme and authority MUST be lowercase and include the port number; http default port 80 and https default port 443 MUST be excluded.

For example, the request:
HTTP://Example.com:80/resource?id=123
Is included in the Signature Base String as:
http://example.com/resource

Parameters:
url - the url to be normalized
Returns:
the Signature Base String
See Also:
OAuth Core - 9.1.2. Construct Request URL

setConsumerKey

public void setConsumerKey(String consumerKey)

setConsumerSecret

public void setConsumerSecret(String consumerSecret)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.