Using Authentication Using Ajax.Request

I currently have a Palm webOS application that uses Ajax.Request to connect to a web service using basic authentication. To send username and password, I just include it in the url (i.e. http: // username: password@ip-address : port / ), which works very well, expect the password to contain anything other than alphanumeric characters (for example, I recently had the email address of a user who included “@” and “&” in his password, and he was unable to connect because the characters were not processed properly for the URL). Is there a way to send the credentials in the url so that I can allow users to use something other than alphanumeric in their passwords?

var username = cookie.get().servers[this.serverIndex].username; var password = cookie.get().servers[this.serverIndex].password; this.auth = 'Basic ' + Base64.encode(username + ':' + password); var baseUrl = 'http://' + url + ':' + port + '/gui/'; this.baseUrl = baseUrl; var request = new Ajax.Request(this.tokenUrl, { method: 'get', timeout: 2000, headers: { Authorization: this.auth }, onSuccess: successFunc, onFailure: this.failure.bind(this) }); 

Answer (I removed the URL for security reasons):

 {"request": {"options": {"method": "get", "asynchronous": true, "contentType": "application/x-www-form-urlencoded", "encoding": "UTF-8", "parameters": {}, "evalJSON": true, "evalJS": true, "timeout": 2000, "headers": {"Authorization": "Basic c3VubW9yZ3VzOmZyb2dneUAlMjY="}}, "transport": {"readyState": 4, "onloadstart": null, "withCredentials": false, "onerror": null, "onabort": null, "status": 401, "responseXML": null, "onload": null, "onprogress": null, "upload": {"onloadstart": null, "onabort": null, "onerror": null, "onload": null, "onprogress": null}, "statusText": "", "responseText": "", "UNSENT": 0, "OPENED": 1, "HEADERS_RECEIVED": 2, "LOADING": 3, "DONE": 4}, "url": "" 
+2
source share
2 answers

Submit basic authentication information with a headline: http://coderseye.com/2007/how-to-do-http-basic-auth-in-ajax.html

 var auth = 'Basic ' + Base64.encode(user + ':' + pass); Ext.Ajax.request({ url : url, method : 'GET', headers : { Authorization : auth } }); 
+3
source

You can try to encode the username and password before sending them using encodeURIComponent .

In general, although you tested this method in IE8? Because it no longer works for regular requests - the username: password@ scheme is disabled for security reasons.

It may, however, be that they are still allowed in Ajax requests.

0
source

Source: https://habr.com/ru/post/1498692/


All Articles