Fork us on GitHub

Google Login

This tutorial covers how to add Google+ connect to your CN1 app

Codename One supports google Oauth2 login and Google+ single sign on for iOS and Android

To get started first you will need to create a google project on the google console
Here: https://console.developers.google.com

Your google project should have 3 client ID's configured for web application, iOS application and Android application

Web application:
Android Settings:
iOS Settings:

The settings page should look like this:




In your CodenameOne app do the following:
Add
ios.gplus.clientId=<your ios client ID>
build hints to your project properties
and in your code do the following:

                
                //This is the web client id, which will be used on the Simulator 
                String clientId = "839004709667-n9el6dup3gono67vhi5nd0dm89vplrka.apps.googleusercontent.com";
                String redirectURI = "https://www.codenameone.com/oauth2callback";
                String clientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXX";
                Login gc = GoogleConnect.getInstance();
                gc.setClientId(clientId);
                gc.setRedirectURI(redirectURI);
                gc.setClientSecret(clientSecret);
                gc.setCallback(...);
                if(!gc.isUserLoggedIn()){
                    gc.doLogin();
                }else{
                    //get the token and now you can query the gplus API
                    String token = gc.getAccessToken().getToken();
                    ...
                }