javascriptrestaxios

axios how to send windows authentication headers to API


I have an API deployed to the server. Authentication is set to "Windows Authentication" but when I send a request using axios it returns

401 - Unauthorized: Access is denied due to invalid credentials.

How can I send a request with the headers for windows authentication?

axios.get('http://ir-devtestsvr/FantasticDashboard/api/p/getDataA')
     .then(r=>{
       this.data = r.data
       if(typeof(cb)== 'function'){
         cb()
       }
     })

can someone point me in the right direction


Solution

  • The 401 is a challenge to authenticate, the server or proxy is saying, to access to this resource you need to authenticated it should also tell you what authentication schemes it supports

    for example for Windows its either Kerberos / NTLM or both If you view the response in Fiddler or another HTTP inspector you should see at least one of the 2 below, that's a good starting point

    Your browser should then send another request automatically with the token for example like this image from this site

    Once your site is setup in IIS and you have ticked Windows authentication, you should not need to do anything else, unless there is a config issue, your proxy or your web server needs looking at.

    see here for an explanation of how the 401 challenge works see here for a windows auth headers & flow see here & here for how chrome & firefox implement