question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios is sending the Authorization header in preflight requests

See original GitHub issue

Summary

Axios is sending the Authorization header in preflight requests, which it shouldn’t

There should be an option to enable/disable this

The error is Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.

This doesn’t work (the jquery ajax alternative works)

    HTTP.get("http://mysite.com/",{
      responseType: 'text',
      withCredentials: true,
      auth: {
        username: "abcd",
        password: "1234"
      }
    })
    .then(response => {});

This works (after entering the username and password in the pop up)

    HTTP.get("http://mysite.com/",{
      responseType: 'text',
      withCredentials: true,
      /*auth: {
        username: "abcd",
        password: "1234"
      }*/
    })
    .then(response => {});

Context

  • axios version: 0.18.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

4reactions
chinesedfancommented, Dec 7, 2019

CORS problem, instead of an axios issues.

2reactions
Maksiocommented, Dec 15, 2018

I decide this issue with setting server’s answer $response->headers->add('Access-Control-Allow-Headers', 'Authorization, Content-Type');

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send authorization header with axios - Stack Overflow
I have tried a few things without success, for example: const header = `Authorization: Bearer ${token}`; return axios. get(URLConstants. USER_ ...
Read more >
Using Axios to set request headers - LogRocket Blog
Learn different ways Axios can be used to set request headers for API calls. ... This code sets authorization headers for all requests:...
Read more >
How to send the authorization header using Axios
To set headers in an Axios POST request, pass a third object to the axios.post() call. You might already be using the second...
Read more >
axios has been blocked by cors policy: response to preflight ...
Solution 1: Access-Control-Allow-Origin is a response header - so in order to enable CORS - We need to add this header to the...
Read more >
Preflight request - MDN Web Docs Glossary: Definitions of ...
A CORS preflight request is a CORS request that checks to see if the CORS protocol is understood and a server is aware...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found