Flask-praetorian, not able to pass auth header to protected endpoint Flask-praetorian, not able to pass auth header to protected endpoint flask flask

Flask-praetorian, not able to pass auth header to protected endpoint


(Author of the flask-praetorian package here)

The issue here is that you are just calling the profile() method from your login() method. Calling pack_header_for_user will not actually put the correct auth headers in the current request context. Instead, it just creates a header dict that could be put into a request (but is nicely returned as json). You could jam the token into the current request by tinkering with flask's request context, but it would not be the best way.

The right way to do this is to have your login route include the token in your response payload and then to make another call from your frontend code to the profile endpoint with the token added to the request header.

Really, I think you would be better off going with a different package like flask-security. The flask-praetorian package is intended to be used with pure APIs, and I haven't done any testing or prototyping with standard flask pages.