Search code examples
pythonangularjsflaskrestful-architecture

Flask API blocking OPTIONS requests


I have an API written in Flask, when I am trying to use this API from AngularJS I am getting an 401 error unauthorized, same request with same credentials is working fine from Postman or HTTPie. This is happening with GET or POST request.

I noticed that the difference between HTTPie and Angular request is that Angular is calling OPTIONS before a GET request.

This is my python code where authentication is required(api is a blueprint):

@api.before_request
@rate_limit(limit=5, period=15)
@auth_token.login_required
def before_request():
   """All routes in this blueprint require authentication."""
   pass

The only method that is working from my api is one that is outside of this blueprint, my conclusion is that the @api.before_request and @auth_token.login_required are expecting credentials to be sent for the OPTIONS request, any idea what can I do?

Thank you very much


Solution

  • I figure out the problem, I solved after updating the plugin Flask-HTTPAuth.

    I was having the version 2.2.1 and after moving to 3.2.1 it solved.

    Tried the same on an instance of Amazon EC2 and solved with the same solution so I am quite sure it was this.