Still cannot get Authorization to work
See original GitHub issueI am currently developing a new web application with Vue.js and I am using axios for the REST API communication.
The API is on a server protected by basic auth and I cannot manage to get axios working with the Authorization header.
I tried it the way as described in https://github.com/axios/axios/issues/1769 and it did not work:
const axiosInstance = axios.create({
//method: 'GET',
baseURL: process.env.API_BASE_URL,
'Content-Type': 'application/json'
});
console.log(axiosInstance.defaults.headers);
// Alter defaults after instance has been created
axiosInstance.defaults.headers.common['Authorization'] = 'Basic xxxx';
axiosInstance.defaults.headers.common['X-ABC'] = "bla bla bla";
axiosInstance.get(url)
.then(response => {
this.groups = response.data
})
.catch(e => {
console.log(e);
this.errors.push(e)
});
I tried it like this and it did not work
axios.get(url, [{
headers: {
"Authorization": "Basic xxxx"
}
}])
.then(response => {
this.groups = response.data
})
.catch(e => {
this.errors.push(e)
})
I tried it like this and it did not work
axios({
"url": url,
"method": "GET",
"headers": {
"Authorization": "Basic xxx"
}
})
.then(response => {
this.groups = response.data
})
.catch(e => {
this.errors.push(e)
})
They all return 401 HTTP error.
I am hitting my limit frustrated because to what the problem is.
Can anybody help me give me a very clear example and tell me where the problem lies?
Looking at the console, it seems the headers do not get sent out!
Context
- axios version: e.g.: v0.18.0
- Environment: e.g.: v6.12.3, Mac OS SX
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
What if My Employee Doesn't Have Work Authorization?
Generally speaking, you are free to place on unpaid leave any employee or new hire who cannot provide proof of their employment authorization....
Read more >Proving Work Authorization & Reverification
That is, the employer cannot require you to present another work permit with the new expiration date as long as you have other...
Read more >Handling Employment Authorization Document Delays - SHRM
If USCIS is unable to issue the EAD within 90 days, it must produce an “interim” document to allow the foreign national to...
Read more >Still No Work Permit?!?! - YouTube
Work permit delays have been happening across the board. We know how stressful it is for you to live in a state of...
Read more >Employment Authorization Document (EAD), Explained
Prove you can legally work in the United States with form I-766, the Employment Authorization Document (EAD), also known as a Work Permit....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
is displayed in the console.Might this be a problem on the server side, that CORS is not enabled but chrome still prevents?
@AnnoyedDeveloper
axios
has a documented option for basic authentication calledauth
. It is documented in the request config section of the readme.From the readme:
So, something like this: