Core functions

Below is all core functionality included in the SDK. All functions resides in the namespace Boka and should be prefixed as such.

init()

Description:

The init() command is used to configure the SDK with information used throughout subsequent communication.

Info

Important! init() must be called before subsequent use of any function in the SDK.

Usage:

Boka.init(options);

Where options is an object containing the following properties.

Key Value
app Identifier of your application. Provided by Boka.se support.
[autoLogin] Boolean value indicating if the SDK should try to automatically log you in using a securely stored refresh token, in case the user's credentials have expired. The default value is false.
[autoLoginCallback] A function called when the SDK has completed the above login process.
An object containing login data is passed as a parameter to this function. The data contains the properties Name, Email and access_token.
Note! This will also be called with the current credentials, should these be valid.

Example:

Boka.init({
    app: 'Your app key',
    autoLogin: true,
    autoLoginCallback: function(loginData) {
        if (loginData.success)
            console.log('Welcome ' + loginData.result.Name + '!');
    }
});

For a deeper explanation of the autoLogin feature, see the page authentication using refresh token for a deeper explanation of the various authentication methods.

login()

Description:

The login() command is used to authenticate the user through the Boka API. Please see the authentication pages for a deeper explanation of the various authentication methods.

Usage:

Boka.login(options);

Where options is an object containing the following properties.

Key Value
method Can be one of the following alternatives: 'window', 'password', 'facebook' or 'google'.

'window' opens a pre-styled window that will automatically handle all authentication options.

'password' requires that the properties [username] and [password] are supplied.

'facebook' and 'google' will initiate an OAuth process through Boka's servers and redirect the user to the URL specified by the [redirect_url] property. This page will then need to call the SDK function handleLoginCallback().
[callback] A function called when using either the 'window' or 'password' methods.
If successful, the result property of the passed parameter will contain login data. This data contains the properties Id, Name, Email.
[username] The user name (e-mail address) for the user. Can be omitted for all but the 'password' method.
[password] The password for the user. Can be omitted for all but the 'password' method.
[redirect_url] A relative URL in your application that the user will land on after being routed through the OAuth process used by either 'facebook' or 'google' methods. Can be omitted for all but these methods.

Callback response:

Key Data type Value
Id string User Id.
Name string User first and last name.
Email string User e-mail address.

Example using a popup window:

Boka.login({
    method: 'window',
    callback: function(loginData) {
        if (loginData.success) 
            console.log('Welcome ' + loginData.result.Name + '!');
    }
});

Example using username and password:

Boka.login({
    method: 'password',
    username: 'johndoe@boka.se',
    password: 'eodnhoj',
    callback: function(loginData) {
        if (loginData.success) 
            console.log('Welcome ' + loginData.result.Name + '!');
    }
});

Example using Facebook:

Boka.login({
    method: 'facebook',
    redirect_url: '/login_complete'
});
Boka.handleLoginCallback(function (loginData) {
    if (loginData.success) 
        console.log('Welcome ' + loginData.result.Name + '!');
});

handleLoginCallback()

Description:

The handleLoginCallback() command is used to handle the response generated by the OAuth process of the Boka servers.

Usage:

Boka.handleLoginCallback(callback);

Where callback is a function called with a parameter containing the login data.

Response:

Key Data type Value
Id string User Id.
Name string User first and last name.
Email string User e-mail address.

Example:

Boka.handleLoginCallback(function (loginData) {
    if (loginData.success) 
        console.log('Welcome ' + loginData.result.Name + '!');
});

logout()

Description:

The logout() command is used to sign off any authorization against the Boka API.

Usage:

Boka.logout(callback);

Where callback is a function called upon logout completion.

Example:

Boka.logout(function () {
    console.log('Logout completed.');
});