1

I'd like to add an X-CSRF token to some $resources, but even though I've been looking to other topic and found taht I could add header this way

return $resource(url, {}, {
              connect: {
                method: 'POST',
                headers: {'headerName': value}
              }
            });

However I don't have the X-CSRFToken added in the request headers when I set headerName to CSRF-TOKEN or crsftoken, (same goes for X-CSRF-TOKEN)

Do someone has an idea why it's not working ?

Edit1: I've seen that add a cookie named XSRF-TOKEN added an header X-XSRF-TOKEN to my requests but CSRF-TOKEN does not.

Antoine
  • 35
  • 7

1 Answers1

0

Here is an example

this.exampleFunction = function (csrf) {
    return $resource(url, null, {
        'update': {'method': 'POST', headers: {'HTTP_X_CSRFTOKEN': csrf}},
    });
};

The header name may be different depending on the back end. For Django it may be 'X-CSRFToken' or 'HTTP_X_CSRFTOKEN'.

Olexiy
  • 535
  • 1
  • 7
  • 14