I'm trying to add a Authorization header to my get request from my react app to Spring boot back-end. I've tried both fetch and axios:
fetch('http://127.0.0.1:8080/api/tender', {
method: 'GET',
headers: {
Authorization: 'Bearer' + token,
'Access-Control-Allow-Origin': '*'
}
});
axios.defaults.headers.common['Authorization'] = 'Bearer' + token;
axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
axios.get('http://127.0.0.1:8080/api/tender').then((res) => console.log(res));
My raw header viewed from devtools:
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0
Accept-Language: nb-NO,nb;q=0.9,no-NO;q=0.8,no;q=0.6,nn-NO;q=0.5,nn;q=0.4,en-US;q=0.3,en;q=0.1
Accept-Encoding: gzip, deflate
Access-Control-Request-Method: GET
Access-Control-Request-Headers: access-control-allow-origin,authorization
Referer: http://localhost:3000/import
Origin: http://localhost:3000
DNT: 1
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: */*
Somehow my custom headers are removed before calling the api and I get the following error: Missing security token, please log in
If I edit and resend the same reuqest adding Authorization to my header, the api reponds with 200
Edit:
Ignoring token validation for http Options method gives a 200 response. But my initial request never runs. I would expect my get-request to run as soon as the option method returns OK