Token Authentication

In some cases it’s not possible to send the credentials in every request. For these cases there is a Token authentication. Before a program starts using the API, it authenticates with basic Authentication, and requests a Token from the server. From that point, there is no need for Basic authentication on every request if the token is presented in the HTTP header. This way the Token is sent over the network in every request, similar to the basic authentication, but no user name, or password is transmitted. Token has an Expiry time. If it’s not used for 5 hours, it expires.

To Authenticate with Token, first you need to get a Token using the API method mentioned below. After you have a token, put that Token to the HTTP Header. The name has to be “Token” and value should be the TokenString you got with the Token.

Token Methods

Object Representation

public class TokenObject
{
    public string TokenString;
    public string UserEmail;
    public DateTime ExpirationTime;
}  

Sample Token Authentication in jQuery

function _ajax_request(url, data, callback, type, method)
{    
    if (jQuery.isFunction(data))
    {
        callback = data;
        data = {};
    }
    return jQuery.ajax({
        type: method,
        url: url,
        data: data,
        beforeSend : function(req) {
            req.setRequestHeader(‘Token’, "40a6c903562946c8a32cf752011e8f11");
        },
        success: callback,
        dataType: type
    });
}