Really simple question but I couldn't find anything anywhere about this.
I'm trying to make a fetch request with the original authentication header.
My app is using http basic authentication for all routes which works fine.
with my clientside js I'm trying to create a request to /api/thing
which requires the same http basic credentials as the original page request.
How do I pass those original credentials aloing withthe request?
fetch("http://localhost:33507/api/thing")
.then(function(response) {
return response.text()
})
.then(function(responseText) {
console.log(responseText);
});
edit: I know I can pass headers like so:
fetch("http://localhost:33507/ssh", {headers: {"Authorization": "basic u:p"}})
But that's not the issue, the issue is getting the username and password. I can't really ask the user to fill them in on every request. Surely there is a way to pass them along without looking at them?
edit2: my flow is like this:
1 user requests page - server asks for http basic credentials.
2 user sends credentials - server replies with page.
3 user presses button to send fetch request - server replies with resource.
The problem here is that I can't find a way to pass those credentials when doing the fetch request