public class

GoogleAuthTokenFactory

extends Object
implements AuthTokenFactory
java.lang.Object
   ↳ com.google.gdata.client.GoogleAuthTokenFactory

Class Overview

A factory for creating Google authentication tokens (ClientLogin and AuthSub).

Summary

Nested Classes
class GoogleAuthTokenFactory.AuthSubToken Encapsulates the token used by web applications to login on behalf of a user. 
class GoogleAuthTokenFactory.OAuth2Token Encapsulates the OAuth 2.0 information used by applications to login on behalf of a user. 
class GoogleAuthTokenFactory.OAuthToken Encapsulates the OAuth information used by applications to login on behalf of a user. 
class GoogleAuthTokenFactory.UserToken The UserToken encapsulates the token retrieved as a result of authenticating to Google using a user's credentials. 
Constants
String GOOGLE_ACCOUNTS_PATH The path name of the Google accounts management handler.
String GOOGLE_LOGIN_PATH The path name of the Google login handler.
Fields
private String applicationName
private HttpAuthToken authToken
private String domainName
private String loginProtocol
private String password
private String serviceName
private AuthTokenFactory.TokenListener tokenListener
private String username
Public Constructors
GoogleAuthTokenFactory(String serviceName, String applicationName, AuthTokenFactory.TokenListener tokenListener)
Constructs a factory for creating authentication tokens for connecting to a Google service with name serviceName for an application with the name applicationName.
GoogleAuthTokenFactory(String serviceName, String applicationName, String protocol, String domainName, AuthTokenFactory.TokenListener tokenListener)
Constructs a factory for creating authentication tokens for connecting to a Google service with name serviceName for an application with the name applicationName.
Public Methods
String getAuthToken(String username, String password, String captchaToken, String captchaAnswer, String serviceName, String applicationName, ClientLoginAccountType accountType)
Retrieves the authentication token for the provided set of credentials.
HttpAuthToken getAuthToken()
Get an authentication token.
String getAuthToken(String username, String password, String captchaToken, String captchaAnswer, String serviceName, String applicationName)
Retrieves the authentication token for the provided set of credentials for either a Google or a hosted domain.
void handleSessionExpiredException(GoogleService.SessionExpiredException sessionExpired)
Handles a session expired exception.
static String makePostRequest(URL url, Map<String, String> parameters)
Makes a HTTP POST request to the provided url given the provided parameters.
void setAuthSubToken(String token)
Sets the AuthSub token to be used to authenticate a user.
void setAuthSubToken(String token, PrivateKey key)
Sets the AuthSub token to be used to authenticate a user.
void setAuthToken(HttpAuthToken authToken)
Set the authentication token.
void setOAuth2Credentials(Credential credential)
Sets the OAuth 2.0 credentials used to generate the authorization header.
void setOAuthCredentials(OAuthParameters parameters, OAuthSigner signer)
Sets the OAuth credentials used to generate the authorization header.
void setUserCredentials(String username, String password, String captchaToken, String captchaAnswer)
Sets the credentials of the user to authenticate requests to the server.
void setUserCredentials(String username, String password)
Sets the credentials of the user to authenticate requests to the server.
void setUserCredentials(String username, String password, ClientLoginAccountType accountType)
Sets the credentials of the user to authenticate requests to the server.
void setUserCredentials(String username, String password, String captchaToken, String captchaAnswer, ClientLoginAccountType accountType)
Sets the credentials of the user to authenticate requests to the server.
void setUserToken(String token)
Sets the AuthToken that should be used to authenticate requests to the server.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.gdata.client.AuthTokenFactory

Constants

public static final String GOOGLE_ACCOUNTS_PATH

The path name of the Google accounts management handler.

Constant Value: "/accounts"

public static final String GOOGLE_LOGIN_PATH

The path name of the Google login handler.

Constant Value: "/accounts/ClientLogin"

Fields

private String applicationName

private HttpAuthToken authToken

private String domainName

private String loginProtocol

private String password

private String serviceName

private AuthTokenFactory.TokenListener tokenListener

private String username

Public Constructors

public GoogleAuthTokenFactory (String serviceName, String applicationName, AuthTokenFactory.TokenListener tokenListener)

Constructs a factory for creating authentication tokens for connecting to a Google service with name serviceName for an application with the name applicationName. The default domain (www.google.com) will be used to authenticate.

Parameters
serviceName The name of the Google service to which we are connecting. Sample names of services might include "cl" (Calendar), "mail" (GMail), or "blogger" (Blogger)
applicationName The name of the client application accessing the service. Application names should preferably have the format [company-id]-[app-name]-[app-version]. The name will be used by the Google servers to monitor the source of authentication.
tokenListener Listener for token changes

public GoogleAuthTokenFactory (String serviceName, String applicationName, String protocol, String domainName, AuthTokenFactory.TokenListener tokenListener)

Constructs a factory for creating authentication tokens for connecting to a Google service with name serviceName for an application with the name applicationName. The service will authenticate at the provided domainName.

Parameters
serviceName The name of the Google service to which we are connecting. Sample names of services might include "cl" (Calendar), "mail" (GMail), or "blogger" (Blogger)
applicationName The name of the client application accessing the service. Application names should preferably have the format [company-id]-[app-name]-[app-version]. The name will be used by the Google servers to monitor the source of authentication.
protocol Name of protocol to use for authentication ("http"/"https")
domainName The name of the domain hosting the login handler
tokenListener Listener for token changes

Public Methods

public String getAuthToken (String username, String password, String captchaToken, String captchaAnswer, String serviceName, String applicationName, ClientLoginAccountType accountType)

Retrieves the authentication token for the provided set of credentials.

Parameters
username The name of the user (an email address)
password The password of the user
captchaToken The CAPTCHA token if CAPTCHA is required (Optional)
captchaAnswer The respective answer of the CAPTCHA token (Optional)
serviceName The name of the service to which a token is required
applicationName The application requesting the token
accountType The account type: HOSTED, GOOGLE, or HOSTED_OR_GOOGLE
Returns
  • the token
Throws
AuthenticationException if authentication failed

public HttpAuthToken getAuthToken ()

Get an authentication token.

Returns
  • Authentication token.

public String getAuthToken (String username, String password, String captchaToken, String captchaAnswer, String serviceName, String applicationName)

Retrieves the authentication token for the provided set of credentials for either a Google or a hosted domain.

Parameters
username The name of the user (an email address)
password The password of the user
captchaToken The CAPTCHA token if CAPTCHA is required (Optional)
captchaAnswer The respective answer of the CAPTCHA token (Optional)
serviceName The name of the service to which a token is required
applicationName The application requesting the token
Returns
  • the token
Throws
AuthenticationException if authentication failed

public void handleSessionExpiredException (GoogleService.SessionExpiredException sessionExpired)

Handles a session expired exception.

Parameters
sessionExpired

public static String makePostRequest (URL url, Map<String, String> parameters)

Makes a HTTP POST request to the provided url given the provided parameters. It returns the output from the POST handler as a String object.

Parameters
url The URL to post the request
parameters The parameters to post to the handler
Returns
  • the output from the handler
Throws
IOException if an I/O exception occurs while creating, writing, or reading the request

public void setAuthSubToken (String token)

Sets the AuthSub token to be used to authenticate a user.

Parameters
token The AuthSub token retrieved from Google

public void setAuthSubToken (String token, PrivateKey key)

Sets the AuthSub token to be used to authenticate a user. The token will be used in secure-mode, and the provided private key will be used to sign all requests.

Parameters
token The AuthSub token retrieved from Google
key The private key to be used to sign all requests

public void setAuthToken (HttpAuthToken authToken)

Set the authentication token.

Parameters
authToken Authentication token

public void setOAuth2Credentials (Credential credential)

Sets the OAuth 2.0 credentials used to generate the authorization header.

Parameters
credential The OAuth 2.0 credentials to use to generate the header

public void setOAuthCredentials (OAuthParameters parameters, OAuthSigner signer)

Sets the OAuth credentials used to generate the authorization header. The following OAuth parameters are required:

  • oauth_consumer_key
  • oauth_token

Parameters
parameters The OAuth parameters to use to generate the header
signer The signing method to use for signing the header

public void setUserCredentials (String username, String password, String captchaToken, String captchaAnswer)

Sets the credentials of the user to authenticate requests to the server. A CAPTCHA token and a CAPTCHA answer can also be optionally provided to authenticate when the authentication server requires that a CAPTCHA be answered.

Parameters
username The name of the user (an email id)
password The password of the user
captchaToken The CAPTCHA token issued by the server
captchaAnswer The answer to the respective CAPTCHA token
Throws
AuthenticationException if authentication failed

public void setUserCredentials (String username, String password)

Sets the credentials of the user to authenticate requests to the server.

Parameters
username The name of the user (an email address)
password The password of the user
Throws
AuthenticationException if authentication failed.

public void setUserCredentials (String username, String password, ClientLoginAccountType accountType)

Sets the credentials of the user to authenticate requests to the server.

Parameters
username The name of the user (an email address)
password The password of the user
accountType The account type: HOSTED, GOOGLE, or HOSTED_OR_GOOGLE
Throws
AuthenticationException if authentication failed.

public void setUserCredentials (String username, String password, String captchaToken, String captchaAnswer, ClientLoginAccountType accountType)

Sets the credentials of the user to authenticate requests to the server. A CAPTCHA token and a CAPTCHA answer can also be optionally provided to authenticate when the authentication server requires that a CAPTCHA be answered.

Parameters
username The name of the user (an email id)
password The password of the user
captchaToken The CAPTCHA token issued by the server
captchaAnswer The answer to the respective CAPTCHA token
accountType The account type: HOSTED, GOOGLE, or HOSTED_OR_GOOGLE
Throws
AuthenticationException if authentication failed

public void setUserToken (String token)

Sets the AuthToken that should be used to authenticate requests to the server. This is useful if the caller has some other way of accessing the AuthToken, versus calling getAuthToken with credentials to request the AuthToken using ClientLogin.

Parameters
token The AuthToken in ascii form