Appery.io

The Appery.io Developer Hub

Welcome to the Apperyio developer hub. You'll find comprehensive guides and documentation to help you start working with apperyio as quickly as possible, as well as support if you get stuck. Let's jump right in!

Guides    

Social Login

Using Facebook, Twitter and Google for app login.

NOT A CORRECT URL LINK

When building an app with Appery.io, you can use social networks to authenticate users, this can be handy if your app requires registration. Instead of providing new credentials they can use their​ social network login. We currently have the following OAuth supported providers:

  • Twitter
  • Facebook
  • Google

Before You Begin

Before you can complete the following steps you must make sure you have an account with the social media platform you wish your app to connect too.

Creating Your App On The OAuth Provider Side

Make sure you have the user name and password for your social media account before continuing.

Facebook

  1. Go to http://developers.facebook.com/ and log in.
  2. Click My Apps > Add a New App.
  3. Then select Website as the platform.
  4. Enter your Display Name and click Create New Facebook App ID.
  5. Then choose a Category (for example, Apps for Pages) from the drop-down list and click Create App ID.
  6. Once the app is created, to open its settings, go to My Apps > <Your app name> > Settings.
  7. Click Choose a Platform. Choose Website. Use the following Site URL as a template, but use your own Appery.io App ID:
https://appery.io/app/view/<YOUR APPERY.IO APP ID>/
  1. The Appery.io App ID can be taken from the Appery.io app URL.

  2. Type appery.io into App Domains and click Save Changes.

Making Your App Public

You should make your app public. Go to the App Review > Status tab, tick the Yes/No button and confirm; otherwise it won’t be live and available to all users.

  1. Use the App ID and App Secret to configure social login feature for the certain Appery.io database.

Twitter

  1. To create a new Twitter app, go to https://apps.twitter.com/. Click Create New App, enter the required information, and click Create your Twitter application.
  2. Then, open the Keys and Access Tokens tab to locate the API Key and API Secret.

​Remember to set up your app Twitter settings to have read-and-write access, allow the app to sign-in with Twitter, and generate your access token and secret access token.
If the login doesn’t work, try adding the valid callback URL, like this:

https://appery.io/app/view/<YOUR APPERY.IO APP ID>/login.html

Google

OAuth Login with Google App in Android/iOS Apps

Since April 20, 2017, all OAuth requests through InAppBrowser have been blocked (see Google blog for details). The only option to login via Google on a device is to use Google Sign-In Cordova/PhoneGap plugin. However, it's necessary to use the standard web application login flow to login to the web browser. This is why we suggest two different flows for login - on device and on preview. As a result, you need to deceive both Device Client Id and Preview Client Id if you want to use login both on devices and on preview.

Setup Google login on devices

To create projects with Google, you need to register with https://console.developers.google.com first.

  1. Select a project or create a new one, naming it (here: ApperyioGoogle) and accepting the terms of usage.
  2. To make the social login work, Google+ API should be turned on. Go to https://console.developers.google.com and choose Google+ API at the Social APIS section.
  3. In the window that opens, click the Enable button.
  4. Now, go to the main console developers page again and find the Credentials link on the left. Follow that link.
  5. Here you can find the dropdown-button, called Create credentials. Click it and choose OAuth client ID.

​6. Google will ask you to set a product name on the consent screen. So, press the Configure consent screen blue button.

  1. In the dialog that opens, fill in the Product name shown to users field. For example, input Appery.io. Then click Save.
  1. Now, in the new screen, check the Android radio button​.
  2. Go to https://appery.io/app/res page.
  3. Find your Android certificate and click the Export to zip button.
  4. Save the archive to your computer and extract its files.
  5. Copy the contents of <cert_name>.sha1 file and paste them to the Signing-certificate fingerprint input.

Signing-certificate fingerprint

For debug builds, Signing-certificate fingerprint will be the same for all projects:
3A:3a:E8:93:DC:0a:ED:37:E3:a8:5C:1c:51:0c:A5:f4:DB:a0:CE:63
For release builds, Signing-certificate fingerprint will depend on the certificate you used to sign the application.

  1. Fill in the Package name input and click Create.
  2. There will be a popup with your Device Client Id. It should look like this:
    <unique_id>.apps.googleusercontent.com
  3. On the next steps, you will also need your Reversed Client Id. It's the same as Device Client Id but in the reversed order. It should look like this:
    com.googleusercontent.apps.<unique_id>
  4. Open your project.
  5. Got to Project -> App settings -> Cordova plugins.
  6. Locate Google SignIn, click the corresponding checkbox to activate it. Open Options.
  7. Add the REVERSED_CLIENT_ID parameter. Its value corresponds to your Reversed Client Id.

Project was set up for using social login on devices

You don't need to setup anything on the Databases social login tab to use social login on devices.

Setup Google login on preview

1-7. The same as in Setup Google login on devices section. You don't need to create a new project, if you've already created one.

  1. Now, ot the opened screen, check the Web application radio button​ and click Create.
  2. The area with inputs appears. Input some random application name (ex: ApperyApp) and paste https://appery.io into the Authorized JavaScript origins field. Then click Create.
  1. As a result, you’ll get your client ID and client secret credentials.

Specific authorized redirect URIs should look like the following:

https://appery.io/app/view/<YOUR APPERY.IO APP ID>/
https://appery.io/app/view/<YOUR APPERY.IO APP ID>/SomePage.html
  1. Replace <APPERY-IO-APP-ID> with your app id. It can be found in the browser address string.
  1. After passing the required credentials, click Save. Now, you can use the Preview Client ID and Client Secret to define the social login feature for the certain Appery.io database.

Using your credentials

After your app has been created, use the provided credentials to configure the connection under the database settings: go to Database > Your database > Social connections, turn the toggle on for the needed social network, and specify the needed credentials.

Google provider

For Google provider, you only need to use login on preview. You can just start using Social API to use login on devices.

When a user logs in via a social network, a new user will be created in Users collection of the Appery.io database. Appery.io X-Appery-Session-Token will be returned for further API calls.

Invoking social network API.

Returned token doesn’t allow triggering social network providers API. It’s only valid for Appery.io API calls, for example, the Database REST API. In other words, you won't be able to invoke a Facebook API to get a list of your friends. In order to do this, you will need to setup the standard Facebook login functionality.

Social Login API

Please go to Social Login JavaScript API page.

Authentication Events And Statuses

There are few events and statuses that are generated during the authentication process. You can use these events or status to properly track an authentication phase or hook any custom logic. Status can be retrieved by using the getStatus method.

Initially, authentication status equals to unauthorized. Before starting the authentication procedure, the dbloginstart event fires and the authentication status changes from unauthorized to inProgress.

After getting the response from an Appery.io database or a social network, the dbloginend event fires. Also, the status changes to authorized if successfull or to error in case of a failure.

Normally, when launching an app on a mobile device, the token will be received automatically a few seconds after a user has logged in. The token will be returned as a parameter to the defined callback, but when testing the app in the browser, the app will fully reload after being redirected back from a ​social provider. In this case, callbacks defined in JavaScript will not work:

Apperyio.User.loginFB("FB APP Id", "https://appery.io/app/view/<YOUR-APPERY-IO-APP-ID>/").then(function(token){
 //This code will not work in browser
},function(error) {
 //This code will not work in browser too
});

As all the data in your app was reset, you should also call the setDefaultDB method after this redirect if you’re using it.

As indicated above, a ​token will be received automatically in a few seconds, so rely on the events and status to determine if the authentication was successful or not. For example, add the following code on the Page Load event or the init method if building an AngularJS app.

Apperyio.User.setDefaultDB('5492b499e4b0262b47c39fdc');
 
//If not on the device
if (!(document.URL.indexOf('http://') === -1 && document.URL.indexOf('https://') === -1))
{
    checkStatus();
}
 
function checkStatus()
{
    if (Apperyio.User.getStatus() === "authorized") { //Check if authentication is already finished
 
        Apperyio.navigateTo("startScreen"); //And navgiate to diffferent page
    }
    else
    {
        if (Apperyio.User.getStatus() != "error") //If status not equals to error
        {
            document.addEventListener("dbloginend", function() { //Add event listener on dbloginend and check the status again
                checkStatus();
            });
        }
    }
}

Social Login


Using Facebook, Twitter and Google for app login.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.