# Google Data APIs Client Library (1.43.0)

## com.google.gdata.client
Class GoogleAuthTokenFactory

    java.lang.Object
      com.google.gdata.client.GoogleAuthTokenFactory

All Implemented Interfaces:
  AuthTokenFactory

    public class GoogleAuthTokenFactory

extends java.lang.Object
implements AuthTokenFactory

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

Nested Class Summary
`static class` `GoogleAuthTokenFactory.AuthSubToken` Encapsulates the token used by web applications to login on behalf of a user.
`static class` `GoogleAuthTokenFactory.OAuthToken` Encapsulates the OAuth information used by applications to login on behalf of a user.
`static class` `GoogleAuthTokenFactory.UserToken` The UserToken encapsulates the token retrieved as a result of authenticating to Google using a user's credentials.

Nested classes/interfaces inherited from interface com.google.gdata.client.AuthTokenFactory
`AuthTokenFactory.AuthToken, AuthTokenFactory.TokenListener`

Field Summary
`static java.lang.String` `GOOGLE_ACCOUNTS_PATH` The path name of the Google accounts management handler.
`static java.lang.String` `GOOGLE_LOGIN_PATH` The path name of the Google login handler.

Constructor Summary
`GoogleAuthTokenFactory(java.lang.String serviceName, java.lang.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(java.lang.String serviceName, java.lang.String applicationName, java.lang.String protocol, java.lang.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`.

Method Summary
`HttpAuthToken` `getAuthToken()` Get an authentication token.
`java.lang.String` `getAuthToken(java.lang.String username, java.lang.String password, java.lang.String captchaToken, java.lang.String captchaAnswer, java.lang.String serviceName, java.lang.String applicationName)` Retrieves the authentication token for the provided set of credentials for either a Google or a hosted domain.
`java.lang.String` `getAuthToken(java.lang.String username, java.lang.String password, java.lang.String captchaToken, java.lang.String captchaAnswer, java.lang.String serviceName, java.lang.String applicationName, ClientLoginAccountType accountType)` Retrieves the authentication token for the provided set of credentials.
`void` `handleSessionExpiredException(GoogleService.SessionExpiredException sessionExpired)` Handles a session expired exception.
`static java.lang.String` `makePostRequest(java.net.URL url, java.util.Map<java.lang.String,java.lang.String> parameters)` Makes a HTTP POST request to the provided `url` given the provided `parameters`.
`void` `setAuthSubToken(java.lang.String token)` Sets the AuthSub token to be used to authenticate a user.
`void` `setAuthSubToken(java.lang.String token, java.security.PrivateKey key)` Sets the AuthSub token to be used to authenticate a user.
`void` `setAuthToken(HttpAuthToken authToken)` Set the authentication token.
`void` `setOAuthCredentials(OAuthParameters parameters, OAuthSigner signer)` Sets the OAuth credentials used to generate the authorization header.
`void` `setUserCredentials(java.lang.String username, java.lang.String password)` Sets the credentials of the user to authenticate requests to the server.
`void` `setUserCredentials(java.lang.String username, java.lang.String password, ClientLoginAccountType accountType)` Sets the credentials of the user to authenticate requests to the server.
`void` `setUserCredentials(java.lang.String username, java.lang.String password, java.lang.String captchaToken, java.lang.String captchaAnswer)` Sets the credentials of the user to authenticate requests to the server.
`void` `setUserCredentials(java.lang.String username, java.lang.String password, java.lang.String captchaToken, java.lang.String captchaAnswer, ClientLoginAccountType accountType)` Sets the credentials of the user to authenticate requests to the server.
`void` `setUserToken(java.lang.String token)` Sets the AuthToken that should be used to authenticate requests to the server.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### GOOGLE_ACCOUNTS_PATH

    public static final java.lang.String GOOGLE_ACCOUNTS_PATH

  The path name of the Google accounts management handler.

  See Also:
    Constant Field Values

### GOOGLE_LOGIN_PATH

    public static final java.lang.String GOOGLE_LOGIN_PATH

  The path name of the Google login handler.

  See Also:
    Constant Field Values

Constructor Detail

### GoogleAuthTokenFactory

    public GoogleAuthTokenFactory(java.lang.String serviceName,
                                  java.lang.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

### GoogleAuthTokenFactory

    public GoogleAuthTokenFactory(java.lang.String serviceName,
                                  java.lang.String applicationName,
                                  java.lang.String protocol,
                                  java.lang.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

Method Detail

### setUserCredentials

    public void setUserCredentials(java.lang.String username,
                                   java.lang.String password)
                            throws AuthenticationException

  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.

### setUserCredentials

    public void setUserCredentials(java.lang.String username,
                                   java.lang.String password,
                                   ClientLoginAccountType accountType)
                            throws AuthenticationException

  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.

### setUserCredentials

    public void setUserCredentials(java.lang.String username,
                                   java.lang.String password,
                                   java.lang.String captchaToken,
                                   java.lang.String captchaAnswer)
                            throws AuthenticationException

  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

### setUserCredentials

    public void setUserCredentials(java.lang.String username,
                                   java.lang.String password,
                                   java.lang.String captchaToken,
                                   java.lang.String captchaAnswer,
                                   ClientLoginAccountType accountType)
                            throws AuthenticationException

  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

### setUserToken

    public void setUserToken(java.lang.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

### setAuthSubToken

    public void setAuthSubToken(java.lang.String token)

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

  Parameters:
    `token` - the AuthSub token retrieved from Google

### setAuthSubToken

    public void setAuthSubToken(java.lang.String token,
                                java.security.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

### setOAuthCredentials

    public void setOAuthCredentials(OAuthParameters parameters,
                                    OAuthSigner signer)
                             throws OAuthException

  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 generated the header
    `signer` - the signing method to use for signing the header
  Throws:
    `OAuthException`

### setAuthToken

    public void setAuthToken(HttpAuthToken authToken)

  Set the authentication token.

  Parameters:
    `authToken` - authentication token

### getAuthToken

    public HttpAuthToken getAuthToken()

  Description copied from interface: `AuthTokenFactory`
  Get an authentication token.

  Specified by:
    `getAuthToken` in interface `AuthTokenFactory`
  Returns:
    Authentication token.

### getAuthToken

    public java.lang.String getAuthToken(java.lang.String username,
                                         java.lang.String password,
                                         java.lang.String captchaToken,
                                         java.lang.String captchaAnswer,
                                         java.lang.String serviceName,
                                         java.lang.String applicationName)
                                  throws AuthenticationException

  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

### getAuthToken

    public java.lang.String getAuthToken(java.lang.String username,
                                         java.lang.String password,
                                         java.lang.String captchaToken,
                                         java.lang.String captchaAnswer,
                                         java.lang.String serviceName,
                                         java.lang.String applicationName,
                                         ClientLoginAccountType accountType)
                                  throws AuthenticationException

  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

### makePostRequest

    public static java.lang.String makePostRequest(java.net.URL url,
                                                   java.util.Map<java.lang.String,java.lang.String> parameters)
                                            throws java.io.IOException

  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:
    `java.io.IOException` - if an I/O exception occurs while creating, writing, or reading the request

### handleSessionExpiredException

    public void handleSessionExpiredException(GoogleService.SessionExpiredException sessionExpired)
                                       throws GoogleService.SessionExpiredException,
                                              AuthenticationException

  Description copied from interface: `AuthTokenFactory`
  Handles a session expired exception.

  Specified by:
    `handleSessionExpiredException` in interface `AuthTokenFactory`
  Throws:
    `GoogleService.SessionExpiredException`
    `AuthenticationException`