public class GoogleConnect

  1. Object
  2. Login
  3. GoogleConnect

Sign-in-with-Google for Codename One.

As of 2025 Google replaced the legacy Sign-In SDK with the Google Identity Services (GIS) family of APIs. GIS encourages the OAuth 2.0 authorization code flow with PKCE driven from the system browser – exactly what OidcClient does. New apps should call [#signIn(String, String, String[])] which goes through that modern path and works on every Codename One platform without a native SDK dependency.

The older doLogin() / nativelogin() path remains for source compatibility, and on iOS / Android it still delegates to the native implementation provided by the port (see Ports/iOSPort and Ports/Android). On other platforms the legacy path also now goes through OidcClient instead of the deprecated Oauth2 in-app WebView.

Fields

public static final String GOOGLE_ISSUER = "https://accounts.google.com"Google’s well-known OIDC issuer.

Methods

public static GoogleConnect getInstance()Gets the GoogleConnect singleton instance .
public boolean isNativeLoginSupported()Returns true if this service supports native login.
protected Oauth2 createOauth2()Creates the oauth2 to be used to login in case no native login is available for this service.
public AsyncResource<OidcTokens> signIn(String clientId, String redirectUri, String... scopes)Modern Google sign-in.
protected boolean validateToken(String token)Returns true if the previous granted access token is still valid otherwise false.

Inherited methods

Field details

GOOGLE_ISSUER

public static final String GOOGLE_ISSUER = "https://accounts.google.com"
Google’s well-known OIDC issuer.

Method details

getInstance

public static GoogleConnect getInstance()
Gets the GoogleConnect singleton instance .

Returns

the GoogleConnect instance

isNativeLoginSupported

public boolean isNativeLoginSupported()
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

createOauth2

protected Oauth2 createOauth2()
Creates the oauth2 to be used to login in case no native login is available for this service.

Returns

the Oauth2 to be used to login if no native login available and on the simulator

signIn

public AsyncResource<OidcTokens> signIn(String clientId, String redirectUri, String... scopes)
Modern Google sign-in. Goes through the Google Identity Services OIDC endpoints with PKCE, using the system browser. Works the same on every platform (iOS, Android, JavaSE, Web) provided the platform port wires the system browser native interface; otherwise it falls back to an in-app browser window.

Parameters

clientId String
OAuth 2.0 client ID issued in Google Cloud Console. Use the iOS / Android client for the matching native build, or the Web client when running in the simulator / web port.
redirectUri String
Redirect URI registered for that client. Custom schemes (com.example.app:/oauth2redirect) for mobile; HTTPS for web.
scopes String...
OAuth scopes to request – include openid email profile to get an ID token plus user metadata, plus any Google API scopes you need.

Returns

An AsyncResource resolving to the OidcTokens for the signed-in user.

validateToken

protected boolean validateToken(String token)
Returns true if the previous granted access token is still valid otherwise false.

Parameters

token String
the access token to check

Returns

true of the token is valid