Basic Authentication

Basic Authentication sends user credentials in the header of the HTTP request. It requires https connection.
Every API call that requires authentication has to contain the credentials in the HTTP header. Basically the credential has to be sent every time when the API is called, except when the Authentication is not required. For instance when creating a new User.

Basic Authentication API Methods

Samples

In most of the programming languages HTTP Basic Authentication is standard procedure.
The HTTP Header request must contain an ‘Authorization’ header that carries the credentials (user name and password) encoded in BASE64 format. Details.

A sample how to use basic Authentication in jQuery
//Authentication and Request
function _ajax_request(url, data, callback, type, method)
{
    auth = make_base_auth("mail@mail.com", "password");
    
    if (jQuery.isFunction(data))
    {
        callback = data;
        data = {};
    }
    return jQuery.ajax({
        type: method,
        url: url,
        data: data,
        beforeSend : function(req) {
           req.setRequestHeader(‘Authorization’, auth);
        },
        success: callback,
        dataType: type
    });
}
function make_base_auth(user, password)
{
    var tok = user + ‘:’ + password;
    var hash = Base64.encode(tok);
    return "Basic " + hash;
}
//To Extend jQuery use these functions.
jQuery.extend({
    get_: function(url, data, callback, type)
    {
        return _ajax_request(url, data, callback, type, ‘GET’);
    },
    put_: function(url, data, callback, type)
    {
        return _ajax_request(url, data, callback, type, ‘PUT’);
    },
    post_: function(url, data, callback, type)
    {
        return _ajax_request(url, data, callback, type, ‘POST’);
    },
    delete_: function(url, data, callback, type)
    {
        return _ajax_request(url, data, callback, type, ‘DELETE’);
    }
});

You need Base64 encoder to use this sample.

Other jQuery sample for basic authentication.

C# Sample
private static void Get(string url)
{
    WebRequest myReq = WebRequest.Create(url);
    string username = "mail@mail.com";
    string password = "password";
    string usernamePassword = username + ":" + password;
    CredentialCache mycache = new CredentialCache();
    mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
    myReq.Credentials = mycache;
    myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
    myReq.Method = "GET";
    WebResponse wr = myReq.GetResponse();
    Stream receiveStream = wr.GetResponseStream();
    StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
    string content = reader.ReadToEnd();
}