3

i'm developing a web app sharing a resource between multiple clients . after a fair amount of time searching over the web i chose token based authentication and decided to go with it .

i used AngularJS / interceptors on the clint side to add the token to request header

if ($localStorage.token) {
    config.headers.TOKEN = $localStorage.token;
}
...
// 
return config ; 

and on the server-side , a Flask application using flask-cors to handle Cross origin requests . now the problem is that ever since i added the interceptors part , all request are send as OPTIONS ( regardless of the original method - $http.post() or .. )

i read a similar question but the answer was focused on express and i couldn't manage to fix it here . here is my cors configuration :

cors = CORS(application, resources={r"/api/*": {"origins": "*"}}, allow_headers=['X-Requested-With', 'Content-Type', 'TOKEN', 'Accept'])

other than fixing it , why is this happening ? what role is this OPTIONS Request playing in CORS ?

Community
  • 1
  • 1
kianenigma
  • 1,365
  • 12
  • 20

1 Answers1

1

Options is a request that client library will send to target host to check if requesting host is allowed and what methods are allowed for the resource before the original post put get request is sent.

Manoj Saxena
  • 309
  • 1
  • 3
  • 8