RDB2JS Authenticate

Credit Card module for the RdbHost JavaScript V2 library.
The library can be loaded with a script tag, like:

<script src="https://www.rdbhost.com/vendor/rdbhost/2.1/lib/js/rdbhost-bundle.js"></script>
<script src="https://www.rdbhost.com/vendor/rdbhost/2.1/lib/rdb2-authenticate.js"></script>

A more performant way is to include it in the LAB.JS config:

<script> var $L = $LAB.script('/vendor/rdbhost/2.1/lib/js/rdb2-authenticate.js')</script>

How to Use

To use the rdb2-authenticate module, you need to setup an account on each authentication providers you choose to use. Twitter, Facebook, and Google all support federated identity.

Have the client_key and client_secret data available from the setup.

The confirm_fedauth_login method should be called in the startup code for the app, so it runs when the page loads. It returns a promise that resolves if the page load is the final step of the user's login.

The authentication related functionality is in the Authenticate element of Rdbhost.

var liProm = Rdbhost.Authenticate.confirm_fedauth_login();

liProm.then(function(userData) {
    if (!userData)
		return;

    if (userData.status === 'loggedin') {
        app.user = userData.identifier;
        app.key = userData.key;
    }
    else
        throw new Error('login status: '+userData.status);
}
		

The fedauth_login method is called when the user indicates an intention to login.

$('twitter-login').click(function(e) {
    Rdbhost.Authenticate.fedauth_login('Twitter', window.origin);
    // this function never returns.
}
		

When the fedauth_login method is first exercised, it will interactively populate the server-side fedauth provider table through a web form. You will need the client_key and client_secret from your chosen Auth provider for this.