8

Web API has been created in .Net with Windows Authentication. When am invoking the API in React APP getting 401 Unauthorized. Web API Works fine in the browser with windows authentication.

axios.get('http://.../.../user/Data')
    .then(function (response) {
      console.log(response);
    })
    .catch(function (error) {
      console.log(error);
    });```
6
  • Should be similar to stackoverflow.com/questions/1002179/… Commented Apr 19, 2019 at 16:11
  • 1
    That post is related to Jquery -> if the front-end application is windows authenticated, it will work directly. Can u help me to make the React app windows authenticated. Commented Apr 19, 2019 at 16:16
  • When you say it works fine in the browser you mean it prompts you for your credentials? Commented Apr 19, 2019 at 16:18
  • No it wont, Web API project has been developed in .Net and hosted with 'Windows Authentication', so API will be directly able to access my Windows Login UserName. Commented Apr 19, 2019 at 16:26
  • @Mathan jQuery's $.ajax is essentially the same as axios - both make AJAX calls. React runs in the browser; the issue is when you make an AJAX call to the server. You could replicate this with just axios (no React). Commented Apr 19, 2019 at 16:27

1 Answer 1

4

With fetch I set the credentials: include option. Also, I think the Access-Control-Allow-Credentials header needed to be set on the back-end.

I'm a front-end developer so I'm not sure what all went into configuring the back-end for Windows Authentication.

Sign up to request clarification or add additional context in comments.

3 Comments

In the Back-end Project, authentication is set to Windows. Kindly help me to get it work in Front-end.
What I'm saying is try using withCredentials: true, with Axios since credentials: include worked for me using fetch. But, if I remember correctly, it only worked for me if the Access-Control-Allow-Credential response header was set.
Did you need to set the header? Also, please accept the answer so others can find it more easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.