com.google.gdata.client.authn.oauth
Class OAuthHelper

java.lang.Object
  extended by com.google.gdata.client.authn.oauth.OAuthHelper
Direct Known Subclasses:
GoogleOAuthHelper

public class OAuthHelper
extends java.lang.Object

Helper methods to support the entire OAuth lifecycle, including generating the user authorization url, exchanging the user authenticated request token for an access token, and generating the Authorization http header.

See Also:
OAuth Core 1.0

Constructor Summary
OAuthHelper(java.lang.String requestTokenUrl, java.lang.String userAuthorizationUrl, java.lang.String accessTokenUrl, OAuthSigner signer)
          Create a new OAuthHelper object.
 
Method Summary
 java.lang.String getAccessToken(OAuthParameters oauthParameters)
          Exchanges the user-authorized request token for an access token.
 java.lang.String getAccessToken(java.lang.String queryString, OAuthParameters oauthParameters)
          Exchanges the user-authorized request token for an access token.
 java.lang.String getAccessToken(java.net.URL url, OAuthParameters oauthParameters)
          Exchanges the user-authorized request token for an access token.
 java.lang.String getAccessTokenUrl()
          Get the access token url
 java.lang.String getAuthorizationHeader(java.lang.String requestUrl, java.lang.String httpMethod, OAuthParameters oauthParameters)
          Generates the string to be used as the HTTP authorization header.
 java.lang.String getRequestTokenUrl()
          Get the request token url
 java.lang.String getUserAuthorizationUrl()
          Get the user authorization url
 java.lang.String getUserAuthorizationUrl(OAuthParameters oauthParameters)
          Generates the url which the user should visit in order to authenticate and authorize with the Service Provider.
 void setAccessTokenUrl(java.lang.String url)
          Set the access token url
 void setRequestTokenUrl(java.lang.String url)
          Set the request token url
 void setUserAuthorizationUrl(java.lang.String url)
          Set the user authorization url
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OAuthHelper

public OAuthHelper(java.lang.String requestTokenUrl,
                   java.lang.String userAuthorizationUrl,
                   java.lang.String accessTokenUrl,
                   OAuthSigner signer)
Create a new OAuthHelper object.

Parameters:
requestTokenUrl - the url used to obtain an unauthorized request token
userAuthorizationUrl - the url used to obtain user authorization for consumer access
accessTokenUrl - the url used to exchange the user-authorized request token for an access token
signer - the OAuthSigner to use when signing the request
Method Detail

getAccessTokenUrl

public java.lang.String getAccessTokenUrl()
Get the access token url


setAccessTokenUrl

public void setAccessTokenUrl(java.lang.String url)
Set the access token url


getRequestTokenUrl

public java.lang.String getRequestTokenUrl()
Get the request token url


setRequestTokenUrl

public void setRequestTokenUrl(java.lang.String url)
Set the request token url


getUserAuthorizationUrl

public java.lang.String getUserAuthorizationUrl()
Get the user authorization url


setUserAuthorizationUrl

public void setUserAuthorizationUrl(java.lang.String url)
Set the user authorization url


getUserAuthorizationUrl

public java.lang.String getUserAuthorizationUrl(OAuthParameters oauthParameters)
                                         throws OAuthException
Generates the url which the user should visit in order to authenticate and authorize with the Service Provider. The url will look something like this: https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=CMiJx-LdFxCRkJbvBw&oauth_callback=http%3A%2F%2Fwww.google.com%2F

The following parameter is required in OAuthParameters:

The following parameter is optional:

Parameters:
oauthParameters - the OAuth parameters necessary for this request
Returns:
The full authorization url the user should visit. The method also modifies the oauthParameters object by adding the request token and token secret.
Throws:
OAuthException - if there is an error with the OAuth request
See Also:
OAuth Step 1

getAccessToken

public java.lang.String getAccessToken(java.net.URL url,
                                       OAuthParameters oauthParameters)
                                throws OAuthException
Exchanges the user-authorized request token for an access token. This method parses the user-authorized request token from the authorization response url, and passes it on to getAccessToken(String, OAuthParameters).

The following parameters are required in OAuthParameters:

Parameters:
url - the url to parse the request token from
oauthParameters - OAuth parameters for this request
Returns:
the access token
Throws:
OAuthException - if there is an error with the OAuth request
See Also:
OAuth Step 3

getAccessToken

public java.lang.String getAccessToken(java.lang.String queryString,
                                       OAuthParameters oauthParameters)
                                throws OAuthException
Exchanges the user-authorized request token for an access token. This method parses the user-authorized request token from the authorization response's query string, and passes it on to getAccessToken(OAuthParameters) (The query string is everything in the authorization response URL after the question mark).

The following parameters are required in OAuthParameters:

Parameters:
queryString - the query string containing the request token
oauthParameters - OAuth parameters for this request
Returns:
the access token
Throws:
OAuthException - if there is an error with the OAuth request
See Also:
OAuth Step 3

getAccessToken

public java.lang.String getAccessToken(OAuthParameters oauthParameters)
                                throws OAuthException
Exchanges the user-authorized request token for an access token. Typically, this method is called immediately after you extract the user-authorized request token from the authorization response, but it can also be triggered by a user action indicating they've successfully completed authorization with the service provider.

The following parameters are required in OAuthParameters:

Parameters:
oauthParameters - OAuth parameters for this request
Returns:
The access token. This method also replaces the request token with the access token in the oauthParameters object.
Throws:
OAuthException - if there is an error with the OAuth request
See Also:
OAuth Step 3

getAuthorizationHeader

public java.lang.String getAuthorizationHeader(java.lang.String requestUrl,
                                               java.lang.String httpMethod,
                                               OAuthParameters oauthParameters)
                                        throws OAuthException
Generates the string to be used as the HTTP authorization header. A typical authorization header will look something like this:

OAuth realm="", oauth_signature="SOME_LONG_STRING", oauth_nonce="123456", oauth_signature_method="RSA-SHA1", oauth_consumer_key="www.example.com", oauth_token="abc123", oauth_timestamp="123456"

The following parameters are required in OAuthParameters:

Parameters:
requestUrl - the url of the request
httpMethod - the http method of the request (for example GET)
oauthParameters - OAuth parameters for this request
Returns:
the full authorization header
Throws:
OAuthException - if there is an error with the OAuth request
See Also:
OAuth Authorization Header