Authentication Javascript

It is really simple to build a small website using our API.
We do not care about Same-Origin-Policy so you’re able to build web applications running on web servers, as APPs on mobile devices and as applications at the personal computer.

For this example we provide the code on guthub named 42call-sms.
You need to include some library’s to start over.

Start with the correct date format for the x-date header parameter.

var now = new Date();
date = new Date(now.getTime());
date = date.toISOString();

Then hash the users password with md5.

var passMd5 = CryptoJS.MD5($('#password').val());
passMd5 = passMd5.toString();

Combine the date and the md5 password with an line break and encode it with the md5 password.

var hash = CryptoJS.HmacSHA1(passMd5+"\n"+date, passMd5);
hash = hash.toString(CryptoJS.enc.Base64);

The preparation of the header is done. So fire the request to the api url like /api/rest/v2/?sms.

$.ajax({
    type:"POST",
    headers : {
        "x-date" : date,
        "x-authorization" : $('#inputUsername').val()+":"+hash,
}, 
    data: { act: "sendSms", phonenumbers : '123465798', message : 'hello world!'},
    url: "https://login.42call.com/api/rest/v2/?sms"
}).done(function(data) {
    alert(data);
    $.mobile.loading('hide');
});

Done.
More about SMS here.