1

how can I set CSRF TOKEN in my axios request, I've tried this

// axios.defaults.xsrfCookieName = 'csrftoken';
// axios.defaults.xsrfHeaderName = 'X-XSRF-TOKEN';
const tokenApp = window.localStorage.getItem('token')

const { data: res } = await axios.post(`${URL}`, formData, {  
  withCredentials: true, 
  xsrfHeaderName: 'X-XSRF-TOKEN',
  headers: {
    Authorization: `${tokenApp}`,
    "Content-Type": "multipart/form-data"
  }
});

res.file = `http://20.88.238.192/azure-storage/api/blob/download/?file=${res.nameFile}`;
return res;

but i'm still getting 403 error (forbidden). Do I have to include something else?

Phil
  • 157,677
  • 23
  • 242
  • 245
Jose A.
  • 483
  • 2
  • 7
  • 15
  • When sending `FormData`, [**do not** manually set the content-type header](https://stackoverflow.com/a/68643919/283366) – Phil Jan 12 '22 at 22:16

1 Answers1

0

Authorization: ${tokenApp}

probably needs to be:

Authorization: Bearer ${tokenApp}

But without details on your server side, what framework you are using, and some information about how the authentication is actually setup on the server side, there's no way, apart from guessing, to determine what is wrong.

Squiggs.
  • 4,299
  • 6
  • 49
  • 89
  • While probably correct, the exact format of the authorization header value is at the discretion of the remote service – Phil Jan 12 '22 at 22:09