# Class GoogleConnect

java.lang.Object
com.codename1.social.Login
com.codename1.social.GoogleConnect

public class GoogleConnect extends Login

The GoogleConnect Login class allows the sign in with google functionality. The GoogleConnect requires to create a corresponding google cloud project. To enable the GoogleConnect to sign-in on the Simulator create a corresponding web login - https://developers.google.com/+/web/signin/

To enable the GoogleConnect to sign-in on Android Follow step 1 from here - https://developers.google.com/+/mobile/android/getting-started

To enable the GoogleConnect to sign-in on iOS follow step 1 from here - https://developers.google.com/+/mobile/ios/getting-started

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected Oauth2`
  `createOauth2()`
  Creates the oauth2 to be used to login in case no native login is available for this service.
  `static GoogleConnect`
  `getInstance()`
  Gets the GoogleConnect singleton instance .
  `boolean`
  `isNativeLoginSupported()`
  Returns true if this service supports native login.
  `protected boolean`
  `validateToken(String token)`
  Returns true if the previous granted access token is still valid otherwise false.

  ### Methods inherited from class Login

  `addScopes, connect, doLogin, doLogin, doLogout, getAccessToken, isPreferRedirectPrompt, isUserLoggedIn, nativeIsLoggedIn, nativelogin, nativeLogout, setAccessToken, setCallback, setClientId, setClientSecret, setOauth2URL, setPreferRedirectPrompt, setRedirectURI, setScope, validateToken`
  Modifier and Type
  Method
  Description
  `Login`
  `addScopes(String... scopes)`
  Adds the given scopes to the OAuth2 login request.
  `AsyncResource<Login>`
  `connect()`
  Connects to the login service asynchronously, automatically logging in if not yet logged in.
  `void`
  `doLogin()`
  Logs in the user.
  `void`
  `doLogin(LoginCallback callback)`
  Initiates login using the given single-use callback.
  `void`
  `doLogout()`
  Logs out the current user
  `AccessToken`
  `getAccessToken()`
  The AccessToken of this service
  `boolean`
  `isPreferRedirectPrompt()`
  A flag used by the javascript port to indicate that the login will use a redirect for the prompt instead of a popup.
  `boolean`
  `isUserLoggedIn()`
  Indicates if the user is currently logged in
  `boolean`
  `nativeIsLoggedIn()`
  Indicates if the user is currently logged in.
  `void`
  `nativelogin()`
  Logs in the current user natively.
  `void`
  `nativeLogout()`
  Logs out the current user natively.
  `void`
  `setAccessToken(AccessToken token)`
  Sets the Login access token
  `void`
  `setCallback(LoginCallback lc)`
  Sets the login callback that will receive event callback notification from the API
  `void`
  `setClientId(String id)`
  The client id (appid) which asks to connect
  `void`
  `setClientSecret(String secret)`
  The client secret
  `void`
  `setOauth2URL(String oauth2URL)`
  The oauth2 URL
  `void`
  `setPreferRedirectPrompt(boolean preferRedirectPrompt)`
  A flag used by the javascript port to indicate that the login will use a redirect for the prompt instead of a popup.
  `void`
  `setRedirectURI(String redirectURI)`
  The redirect URI
  `void`
  `setScope(String scope)`
  The authentication scope
  `void`
  `validateToken()`
  This method tries to validate the last access token if exists, if the last token is not valid anymore it will try to login the user in order to get a fresh token The method blocks until a valid token has been granted

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `final Class`
  `getClass()`
  Returns the runtime class of an object.
  `int`
  `hashCode()`
  Returns a hash code value for the object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `String`
  `toString()`
  Returns a string representation of the object.
  `final void`
  `wait()`
  Causes current thread to wait until another thread invokes the method or the method for this object.
  `final void`
  `wait(long timeout)`
  Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
  `final void`
  `wait(long timeout, int nanos)`
  Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

- ## Method Details

  - ### getInstance

    public static GoogleConnect getInstance()

    Gets the GoogleConnect singleton instance .

    ###### Returns

    the GoogleConnect instance

  - ### isNativeLoginSupported

    public boolean isNativeLoginSupported()
    Description copied from class: `Login`

    Returns true if this service supports native login. If implementation returns true here, the nativelogin, nativelogout, nativeIsLoggedIn should be implemented

    ###### Returns

    true if the service supports native login

    Specified by:
      `isNativeLoginSupported` in class `Login`

  - ### createOauth2

    protected Oauth2 createOauth2()
    Description copied from class: `Login`

    Creates the oauth2 to be used to login in case no native login is available for this service.

    ###### Returns

    Overrides:
      `createOauth2` in class `Login`
    Returns:
      the Oauth2 to be used to login if no native login available and on the simulator

  - ### validateToken

    protected boolean validateToken(String token)
    Description copied from class: `Login`

    Returns true if the previous granted access token is still valid otherwise false.

    ###### Parameters

    - `token`: the access token to check

    ###### Returns

    true of the token is valid

    Specified by:
      `validateToken` in class `Login`