Check if a site uses Basic Auth through AJAX

Is there a way to check through AJAX if the website uses basic authorization without letting the browser display the login dialog?

My current call:

$.ajax
    type: 'HEAD'
    url: url
    success: (data) ->
         console.log 'jep'
    error: (jqXHR, textStatus, errorThrown) ->
         console.log 'nope'

This will always display a login dialog if the site uses authorization. However, I just want to know if the site is protected by basic authorization or not. I could not find a way to do this. I know this solution, but I can not edit the server response.

+4
source share
1 answer

Check the headers. If you see something like this:

WWW-Authenticate: Basic realm="protected-area"

... , . .

0

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


All Articles