Controlling basic HTTP authentication with javascript

I want to check if the URL is protected by basic Http authentication using javascript. Here is what I still have:

  function showFailure(){ alert("FAILED ") }
  function showSuccess(){ alert("SUCCESS") }

  var myRequest = new Request({
    url: 'http://localhost/access_protected_HTTP_BASIC', 
    method: 'get', 
    onSuccess: showSuccess,
    onFailure: showFailure
  }).send();

But it does open a browser login popup to access the resource. Is there a way to not trigger this popup?

Thank!

Note. I use mootools in this example, but I would take any javascript example that does the trick :)

+3
source share
2 answers

, . ( MooTools Docs user password .)

, XMLHttpRequest spec :

, , , , .

, , . 401, , .

+7

, , Authorization: Basic *Base64EncodedString*, *Base64EncodedString* is base64Encode(username+':'+password) base64encode. YMMV

0

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


All Articles