Google Data APIs Client Library (1.41.1)



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)
          Deprecated. 
OAuthHelper(java.lang.String requestTokenUrl, java.lang.String userAuthorizationUrl, java.lang.String accessTokenUrl, OAuthSigner signer, OAuthHttpClient httpClient)
          Deprecated. 
OAuthHelper(java.lang.String requestTokenUrl, java.lang.String userAuthorizationUrl, java.lang.String accessTokenUrl, java.lang.String revokeTokenUrl, OAuthSigner signer)
          Create a new OAuthHelper object.
OAuthHelper(java.lang.String requestTokenUrl, java.lang.String userAuthorizationUrl, java.lang.String accessTokenUrl, java.lang.String revokeTokenUrl, OAuthSigner signer, OAuthHttpClient httpClient)
          Create a new OAuthHelper object.
 
Method Summary
 java.lang.String createUserAuthorizationUrl(OAuthParameters oauthParameters)
          Generates the url which the user should visit in order to authenticate and authorize with the Service Provider.
 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.
 void getOAuthParametersFromCallback(java.lang.String queryString, OAuthParameters oauthParameters)
          Helper method which parses a querystring for the OAuth related parameters.
 void getOAuthParametersFromCallback(java.net.URL url, OAuthParameters oauthParameters)
          Helper method which parses a url for the OAuth related parameters.
 java.net.URL getOAuthUrl(java.lang.String baseUrl, java.lang.String httpMethod, OAuthParameters oauthParameters)
          Returns a properly formatted and signed OAuth request url, with the appropriate parameters.
 java.lang.String getRequestTokenUrl()
          Get the request token url
 java.lang.String getRevokeTokenUrl()
          Get the revoke token url
 void getUnauthorizedRequestToken(OAuthParameters oauthParameters)
          Retrieves the unauthorized request token and token secret from the remote server and sets the parameters in the OAuthParameters object.
 java.lang.String getUserAuthorizationUrl()
          Get the user authorization url
 java.lang.String getUserAuthorizationUrl(OAuthParameters oauthParameters)
          Deprecated. Call a combination of getUnauthorizedRequestToken(com.google.gdata.client.authn.oauth.OAuthParameters) and createUserAuthorizationUrl(com.google.gdata.client.authn.oauth.OAuthParameters) instead.
 void revokeToken(OAuthParameters oauthParameters)
          Revokes the user's OAuth token.
 void setAccessTokenUrl(java.lang.String url)
          Set the access token url
 void setRequestTokenUrl(java.lang.String url)
          Set the request token url
 void setRevokeTokenUrl(java.lang.String url)
          Set the revoke 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

@Deprecated
public OAuthHelper(java.lang.String requestTokenUrl,
                              java.lang.String userAuthorizationUrl,
                              java.lang.String accessTokenUrl,
                              OAuthSigner signer)
Deprecated. 

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

OAuthHelper

@Deprecated
public OAuthHelper(java.lang.String requestTokenUrl,
                              java.lang.String userAuthorizationUrl,
                              java.lang.String accessTokenUrl,
                              OAuthSigner signer,
                              OAuthHttpClient httpClient)
Deprecated. 

Create a new OAuthHelper object. This version of the constructor is primarily for testing purposes, where a mocked OAuthHttpClient and OAuthSigner can be specified.

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
httpClient - the OAuthHttpClient to use when making http requests

OAuthHelper

public OAuthHelper(java.lang.String requestTokenUrl,
                   java.lang.String userAuthorizationUrl,
                   java.lang.String accessTokenUrl,
                   java.lang.String revokeTokenUrl,
                   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
revokeTokenUrl - the url used to revoke the OAuth token
signer - the OAuthSigner to use when signing the request

OAuthHelper

public OAuthHelper(java.lang.String requestTokenUrl,
                   java.lang.String userAuthorizationUrl,
                   java.lang.String accessTokenUrl,
                   java.lang.String revokeTokenUrl,
                   OAuthSigner signer,
                   OAuthHttpClient httpClient)
Create a new OAuthHelper object. This version of the constructor is primarily for testing purposes, where a mocked OAuthHttpClient and OAuthSigner can be specified.

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
revokeTokenUrl - the url used to revoke the OAuth token
signer - the OAuthSigner to use when signing the request
httpClient - the OAuthHttpClient to use when making http requests
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


getRevokeTokenUrl

public java.lang.String getRevokeTokenUrl()
Get the revoke token url


setRevokeTokenUrl

public void setRevokeTokenUrl(java.lang.String url)
Set the revoke token url


getUnauthorizedRequestToken

public void getUnauthorizedRequestToken(OAuthParameters oauthParameters)
                                 throws OAuthException
Retrieves the unauthorized request token and token secret from the remote server and sets the parameters in the OAuthParameters object.

The following parameter is required in OAuthParameters:

If the request is successful, the following parameters will be set in OAuthParameters:

Parameters:
oauthParameters - the OAuth parameters necessary for this request.
Throws:
OAuthException - if there is an error with the OAuth request
See Also:
OAuth Step 1

getUserAuthorizationUrl

@Deprecated
public java.lang.String getUserAuthorizationUrl(OAuthParameters oauthParameters)
                                         throws OAuthException
Deprecated. Call a combination of getUnauthorizedRequestToken(com.google.gdata.client.authn.oauth.OAuthParameters) and createUserAuthorizationUrl(com.google.gdata.client.authn.oauth.OAuthParameters) instead.

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=[OAUTHTOKENSTRING]&oauth_callback=http%3A%2F%2Fwww.google.com%2F This method first calls getUnauthorizedRequestToken(OAuthParameters) to retrieve the unauthorized request token, and then calls createUserAuthorizationUrl(OAuthParameters). Users who wish to add a token secret to the callback url should call getUnauthorizedRequestToken(OAuthParameters) first, append the retrieved token secret to the callback url, and then call createUserAuthorizationUrl(OAuthParameters).

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

createUserAuthorizationUrl

public java.lang.String createUserAuthorizationUrl(OAuthParameters oauthParameters)
Generates the url which the user should visit in order to authenticate and authorize with the Service Provider. This method does not modify the OAuthParameters object. The url will look something like this: https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=[OAUTHTOKENSTRING]&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.

getOAuthParametersFromCallback

public void getOAuthParametersFromCallback(java.net.URL url,
                                           OAuthParameters oauthParameters)
Helper method which parses a url for the OAuth related parameters. It expects an OAuth token parameter to exist, while the OAuth token secret may or may not exist, depending on the implementation. The parameters are set in the OAuthParameters object.

Parameters:
url - The url containing the OAuth parameters.
oauthParameters - OAuth parameters for this request

getOAuthParametersFromCallback

public void getOAuthParametersFromCallback(java.lang.String queryString,
                                           OAuthParameters oauthParameters)
Helper method which parses a querystring for the OAuth related parameters. It expects an OAuth token parameter to exist, while the OAuth token secret may or may not exist, depending on the implementation. The parameters are set in the OAuthParameters object.

Parameters:
queryString - the query string containing the OAuth parameters
oauthParameters - OAuth parameters for this request

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:

If the request is successful, the following parameters will be set 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

revokeToken

public void revokeToken(OAuthParameters oauthParameters)
                 throws OAuthException
Revokes the user's OAuth token. The following parameters are required in OAuthParameters: Only tokens obtained by three-legged OAuth can be revoked (in other words, this method is not applicable to two-legged OAuth).

Parameters:
oauthParameters - OAuth parameters for this request.
Throws:
OAuthException - if there is an error with the OAuth request

getOAuthUrl

public java.net.URL getOAuthUrl(java.lang.String baseUrl,
                                java.lang.String httpMethod,
                                OAuthParameters oauthParameters)
                         throws OAuthException
Returns a properly formatted and signed OAuth request url, with the appropriate parameters.

Parameters:
baseUrl - the url to make the request to
httpMethod - the http method of this request (for example, "GET")
oauthParameters - OAuth parameters for this request
Returns:
the OAuth request url
Throws:
OAuthException - if there is an error with the OAuth request