This manual shows the process of registering your application in Gluon Cloud and enabling user authentication in full detail. We’ll use the Comments 2.0 sample to illustrate that.

First Steps

Clone the application from the samples repository. You will find the Comments 2.0 sample in the folder /Comments2.0.

Application Registration

If you want to store and synchronize your data in Gluon Cloud using the Gluon Charm Connect library, you will need to register your application in Gluon Cloud. Go to the Gluon Cloud Product page and click on "Sign up" under "Free". You will see this page:

Access to Gluon Cloud Portal

If you haven’t got an account yet, just fill in the sign up form with a valid email address, and click the Sign Up button.

Sign in to Gluon Cloud Portal

If you already have an account, just log in with your credentials:

Log in to Gluon Cloud Portal

Once you are successfully logged in, you will be able to create a Gluon Application by just providing a name in the form on the Dashboard page, like CommentsFX in this sample.

Create App

If you have more applications, those will be showed here.

An application key and secret will be generated for you when the application is created.

Get the application key and secret tokens

Those strings are unique for your application, and you shouldn’t share them with anyone. If your project is open source, take care of not publishing them.

With key and secret tokens, now on your app you can create your GluonClient:

public class GluonClientProvider {
   // Warning: Don't share these strings
    private static final String APPKEY = "e573c0ff-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
    private static final String APPSECRET = "2b528573-XXXX-XXXX-XXXX-XXXXXXXXXXXX";

    private static GluonClient gluonClient;

    public static GluonClient getGluonClient() {
        if (gluonClient == null) {
            gluonClient = GluonClientBuilder.create()
                    .credentials(new GluonCredentials(APPKEY, APPSECRET))
                    .build();
        }
        return gluonClient;
    }

}

User Authentication

Charm Connect allows you to link your data to an authenticated user. The following authentication methods are available out of the box:

  • Facebook: authenticate users with Facebook

  • Google+: authenticate users with Google+

  • Twitter: authenticate users with Twitter

To enable user authentication, you need to set the correct Authentication value on the StorageService. The default authentication method is PUBLIC, which allows everyone that uses your application to read and write all of your data in Gluon Cloud. Using authentication method USER will show an authentication view the first time the application tries to interact with Gluon Cloud.

// enable user authentication
StorageService storageService = gluonClient.getStorageService();
storageService.authentication(Authentication.USER);

// the next statement will trigger the authentication view
CharmObservableList<Note> notes = storageService.<Note>retrieveList("notes", Note.class, StorageWhere.GLUONCLOUD);

Configuring Login Methods

Configuring the authentication methods that should be enabled for your application can be done from the dashboard page on Gluon Cloud Portal.

  • Click the link login methods displayed at the right side of the application you want to configure

Add login methods
  • At the bottom, choose the desired login method.

Twitter Authentication

To get started with Twitter authentication, you first need to create a new Twitter application.

Access Twitter Apps

Sign in with your Twitter account:

Signing in Twitter Apps

And click the Create New App button at the top right of that page and fill in the application details. Fill the form, adding the name of your application, a short description, and a valid URL.

Create app in Twitter Apps

Finally, use the following link for the Callback URL:

Agree on the developer agreement and click the final button to create the application.

When your application is created, you can access to the Keys and Access Tokens tabs and get these values:

Get tokens from app in Twitter Apps

Copy the Consumer Key (API Key) and the Consumer Secret (API Secret), and back on Gluon Cloud Portal, select twitter as a login method, and paste them on the Network Key and Network Secret fields

Paste tokens from app in Gluon Portal

And click add, you will see the Twitter login method, and you can add more.

View tokens from app in Gluon Portal

Facebook Authentication

To get started with Facebook authentication, you first need to create a new Facebook application.

Sign in with your Facebook account:

Signing in Facebook

Click the Add a New App button at the top right of that page.

Create App Facebook

and select the Website platform. Provide the App ID and click Create New Facebook App ID.

Provide App Id Facebook

Select your application’s category and click Create App ID.

Provide App Category Facebook

Click Skip Quick Start at the top right of the page to skip the quickstart configuration wizard.

Skip App Wizard Facebook

On the application’s dashboard

App Dashboard Facebook

click the Settings button from the menu on the left.

Insert cloud.gluonhq.com in the App Domains. Click in Add Platform, select Website, and set the Site URL to http://gluonhq.com/.

Click Save Changes to apply the configuration settings.

App Settings Facebook

When your application is created, click on Show, to reveal the App Secret token. Insert your Facebook password when promted.

App Tokens Facebook

Copy the Application Id and the App Secret, and back on Gluon Cloud Portal, select facebook as a login method, and paste them on the Network Key and Network Secret fields, and click add.

Gluon Tokens Facebook

Google Authentication

To get started with Google authentication, you first need to create a new Google application.

First, sign in with your Google account

Sign in Google

Click the Create Project button on the top of the page

Create Project Google

and fill the name of the project, and agree with the terms of use:

Provide Project's name Google

Once your application is created, choose APIs & auth → Credentials from the menu on the left-hand side.

For Gluon Cloud, we need to add the Google+ API. From the menu on the left, choose APIs & auth → APIs. Click on Google+ API under the Social APIs category

Select Google+ API Google

and click the Enable API button at the top of the new page.

Enable Google+ API Google

Now, select on the left APIs & auth → Credentials, and click the Add credentials button and choose OAuth 2.0 client ID.

Add Credentials Google

Google asks you to first fill in your application details in the Consent Screen.

Access Consent Screen Google

Provide some details, like an URL and a logo

Fill Consent Screen Google

Then you will be redirected back again to the credentials page.

Application Type Google

Choose Web application as the Application type. Add some name

Enter http://cloud.gluonhq.com in the Authorized JavaScript origins field and http://cloud.gluonhq.com/2/connect/callback/GOOGLE_PLUS in the Authorized redirect URIs field.

Application URLs Google

Click Create. You will see the OAuth client screen. Copy the tokens from there: client ID, and client secret

Application URLs Google

And back on Gluon Cloud Portal, select google_plus as a login method, and paste them on the Network Key and Network Secret fields, and click add.

Gluon Tokens Google

Summary

For Twitter, Facebook or Google+, we have created and authorized an application, obtaining a key and secret tokens from each sotial network. On Gluon’s Portal, we have added the login methods and provided the key and secret tokens obtained from the respective social network.

Gluon Login Methods

The next time you run your application with USER authentication enabled, you will see the authentication view with a list of buttons for all the login methods that are enabled.

App Sign in Methods

The user of the application will be able to select one of them and sign in adding his credentials.