Questions tagged [flask-login]

Flask-Login provides user session management for the python web framework Flask.

Flask-Login provides user session management for the web framework Flask. It handles the common tasks of logging in, logging out, and remembering your users' sessions over extended periods of time.

Flask-Login is not bound to any particular database system or permissions model. The only requirement is that your user objects implement a few methods, and that you provide a callback to the extension capable of loading users from their ID.

It will:

  • Store the active user’s ID in the session, and let you log them in and out easily.
  • Let you restrict views to logged-in (or logged-out) users.
  • Handle the normally-tricky “remember me” functionality.
  • Help protect your users’ sessions from being stolen by cookie thieves.
  • Possibly integrate with Flask-Principal or other authorization extensions later on.

However, it does not:

  • Impose a particular database or other storage method on you. You are entirely in charge of how the user is loaded.
  • Restrict you to using usernames and passwords, OpenIDs, or any other method of authenticating.
  • Handle permissions beyond “logged in or not.”
  • Handle user registration or account recovery.

For detailed information and examples, visit the flask-login documentation.

See also the official Github page.

879 questions
11
votes
3 answers

How is Flask-Login's request_loader related to user_loader?

I apologize in advance for asking a rather cryptic question. However, I did not understand it despite going through a lot of material. It would be great if you could shed some light on this. What is the purpose of a request_loader in flask-login? …
galeej
  • 483
  • 7
  • 21
11
votes
3 answers

How to apply decorator to all blueprint urls in flask

I have a blueprint and some url functions, admin_bp = Blueprint('admin', __name__) @admin_bp.route('/dashboard', methods=['GET', ]) @flask_login.login_required def dashboard(): context = {} page = 'admin/dashboard.html' return…
chenxee
  • 175
  • 2
  • 10
11
votes
1 answer

next_is_valid() doesn't exist in flask-login?

Flask-login doc says we should validate next using next_is_valid(), but I can't find any such method: Warning: You MUST validate the value of the next parameter. If you do not, your application will be vulnerable to open…
rublex
  • 1,763
  • 1
  • 21
  • 43
11
votes
2 answers

how to access form data using flask?

My login endpoint looks like @app.route('/login/', methods=['GET', 'POST']) def login(): if request.method == 'POST': print request.form # debug line, see data printed below user = User.get(request.form['uuid']) if user…
daydreamer
  • 73,989
  • 165
  • 410
  • 667
10
votes
3 answers

Disabling @login_required while unit-testing flask with flask-login

I am unit testing my flask app which uses the flask-login extension. I am setting up all my tests like this using webtest: class TestCase(unittest.TestCase): def setUp(self): app.config['TESTING'] = True self.client =…
efeder
  • 510
  • 5
  • 14
10
votes
1 answer

Flask view raises TypeError: 'bool' object is not callable

I am trying to debug a view in my Flask app that is return a 500 status with the error TypeError: 'bool' object is not callable in the traceback. The view calls login_user from Flask-Login then returns True to indicate that the login was…
StefanE
  • 7,144
  • 9
  • 44
  • 72
10
votes
2 answers

Flask-login not redirecting to previous page

I have seen quite a few questions with this in mind, but haven't been able to address my issue. I have a Flask app with flask-login for session management. And, when I try to view a page without logging in, I get redirected to a link in form of…
wont_compile
  • 803
  • 15
  • 39
10
votes
1 answer

flask-login: Chrome ignoring cookie expiration?

I've got the authentication working with flask-login, but it seems like no matter what I use for the cookie duration in flask, the session is still authenticated. Am I setting the config variables properly for flask-login? I've…
reptilicus
  • 9,765
  • 5
  • 49
  • 71
9
votes
2 answers

Why isn't my current_user authenticated in flask-login?

My goal is to make my home view (/) a login page. Once the user logs in, a different page is render depending on its role. When I login (/auth), I see that the username and password are correctly entered. It then attempts to render /, where it tells…
erip
  • 13,935
  • 9
  • 51
  • 102
9
votes
2 answers

Flask login_user doesn't work with pytest

I'm new to Pytest. I want to test my views which require login (decorated with @login_required). I have following test function: def test_add_new_post(self, client, user): login_user(user) assert current_user == user data = { …
moriesta
  • 1,000
  • 4
  • 16
  • 36
9
votes
2 answers

login_required decorator from flask_login not redirecting to previous page

I am using flask_login for login and logout for an app but the redirection back to the previous page does not seem to be working. I am using the flask.views and login_required as a decorator for views that require user login. However, when I try to…
Avi Das
  • 1,525
  • 1
  • 11
  • 18
9
votes
3 answers

How do I handle login in flask with multiple blueprints?

I have multiple blueprints that needs to be integrated into a single app. I'm using flask-login to handle logins. However I'm confused on how to handle the LoginManager() and the .user_loader for my blueprints. This is my current file…
Andriano winatra
  • 105
  • 1
  • 1
  • 5
9
votes
2 answers

Flask Login and Principal - current_user is Anonymous even though I'm logged in

I'm using Flask Login and Principal for identity and role management. My needs are described straight out of the docs. My code is here: @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): # Set the identity user object …
fansonly
  • 961
  • 3
  • 11
  • 28
9
votes
1 answer

Flask-Admin & Authentication: "/admin" is protected but "/admin/anything-else" is not

I'm trying to customize my Admin views with Flask and Flask-SuperAdmin, however, the index view and subviews are apparently not using the same is_accessible method: EDIT: I managed to figure out what I was doing wrong. I needed to define…
Brian
  • 545
  • 4
  • 16
9
votes
4 answers

Flask Login: TypeError: decoding Unicode is not supported

I am running flask, pymongo and flask-login as a stack. My flask app is running fine locally, but once I deploy it with uwsgi on nginx, I get a strange unicode error from flask_login extension. In short: TypeError: decoding Unicode is not…
Houman
  • 58,044
  • 75
  • 235
  • 407
1 2
3
58 59