PDA

View Full Version : How can I prevent the 401 Authentication dialog for Ajax requests with invalid creds?



Tequiol
2 Mar 2012, 5:04 AM
Hello,

I've an application that authenticates via HTTP (as described in my previous post (http://www.sencha.com/forum/showthread.php?184133-How-can-I-build-an-extended-proxy-for-Ajax-requests&highlight=authorization)). I've a problem when the user enters invalid authorization data, the client calls the function to get the settings on the server. If this function success without errors, the user is logged in. But if the authentication fails, the server throws a 401 missing authorization error. The browser will handle this error. So the default authorization dialog pops up. Can I prevent this default authorization dialog?

Tequiol
5 Mar 2012, 12:35 AM
Does really nobody know the answer?

ostghost
5 Mar 2012, 12:47 AM
Hi,

try to handle exceptions. I use following construction in Sencha Touch. In Ext JS 3 I used similar codein combination with plugin to stock call and recall them after succesful login


Ext.Ajax.on('requestexception', function (conn, response, options) {

switch (response.status) {
case 0 :
Ext.Msg.alert(Loading error!', 'No connection.');
break;
case 401 :
Ext.Msg.alert('Authentication failed!', 'Fill your credentials.');
break;
default :
Ext.Msg.alert('Uups!', 'Error.');
}
});



Btw. There could be problem with options.records length when loading store and receiving 401.

Tequiol
5 Mar 2012, 6:25 AM
Hello,

yes this error handling works after the browser authentication dialog is shown. The script execution is stopped until the user clicks "Cancel" in this dialog. After that the error handler will be executed. I'm looking for a solution that prevents the authentication dialog of the browser.

rfender
1 Nov 2012, 9:22 AM
Hello,

yes this error handling works after the browser authentication dialog is shown. The script execution is stopped until the user clicks "Cancel" in this dialog. After that the error handler will be executed. I'm looking for a solution that prevents the authentication dialog of the browser.

Tequiol, did you find a solution to this?

Tequiol
1 Nov 2012, 9:31 AM
No, I never found a solution for this.

ettavolt
2 Nov 2012, 6:39 AM
Can't your server return just 403 for AJAX requests instead of 401?
Then you will be able to perform proper error handling.