Basic Authentication

19 views
Skip to first unread message

JoJo

unread,
Dec 29, 2009, 9:20:03 PM12/29/09
to Prototype & script.aculo.us
I'm using the Twitter API. It needs the user's username and password
send though the Basic Authentication protocol before that user's
Twitter account can be modified. I've searched for how to do Basic
Authentication on the JS side (I don't want to use curl because of
server load), but I've only found jQuery implementations. Does anyone
know how to convert this to work with Prototype?:

function make_base_auth(user, password) {
var tok = user + ':' + pass;
var hash = Base64.encode(tok);
return "Basic " + hash;
}

var auth = make_basic_auth('myUsername','myPassword');
var url = 'http://example.com';

xml = new XMLHttpRequest();
xml.setRequestHeader('Authorization', auth);
xml.open('GET',url)

Ext.Ajax.request({
url : url,
method : 'GET',
headers : { Authorization : auth }
});

// jQuery
$.ajax({
url : url,
method : 'GET',
beforeSend : function(req) {
req.setRequestHeader('Authorization', auth);
}
});

Reply all
Reply to author
Forward
0 new messages