Changes between Version 13 and Version 14 of UserGuidelinesREST


Ignore:
Timestamp:
08/03/11 22:38:26 (10 years ago)
Author:
Fran Boon
Comment:

AJAX Basic Auth

Legend:

Unmodified
Added
Removed
Modified
  • UserGuidelinesREST

    v13 v14  
    1010
    1111Use pre-emptive authentication, when you need to login.
     12=== AJAX ===
     13
     14Authenticate using:
     15{{{
     16function make_base_auth(user, password) {
     17 var tok = user + ':' + pass;
     18 var hash = Base64.encode(tok);
     19 return 'Basic ' + hash;
     20}
     21
     22var auth = make_basic_auth('username', 'password');
     23var url = 'http://host.domain/eden/controller/function?vars';
     24
     25// RAW
     26request = new XMLHttpRequest();
     27request.setRequestHeader('Authorization', auth);
     28request.open('PUT', url, true); // async=true
     29request.send(bodyContent);
     30
     31// ExtJS
     32Ext.Ajax.request({
     33    url : url,
     34    method : 'GET',
     35    headers : { Authorization : auth }
     36});
     37
     38// jQuery
     39$.ajax({
     40    url : url,
     41    method : 'GET',
     42    beforeSend : function(req) {
     43        req.setRequestHeader('Authorization', auth);
     44    }
     45});
     46}}}
     47
     48Thanks to:
     49 * http://coderseye.com/2007/how-to-do-http-basic-auth-in-ajax.html
     50
    1251=== CURL ===
    1352For testing/PUT using CURL follow the example