{"id":23712254,"url":"https://github.com/powermobileweb/flask-login","last_synced_at":"2025-09-03T17:33:34.127Z","repository":{"id":269077702,"uuid":"172258958","full_name":"powermobileweb/flask-login","owner":"powermobileweb","description":"Flask user session management. https://flask-login.readthedocs.io/","archived":false,"fork":false,"pushed_at":"2019-02-23T20:18:53.000Z","size":53,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-20T18:54:18.582Z","etag":null,"topics":["authentication","flask","login-system","python","session-management"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/powermobileweb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-23T20:10:43.000Z","updated_at":"2023-05-25T09:32:15.000Z","dependencies_parsed_at":"2024-12-20T18:54:21.551Z","dependency_job_id":"bd660e03-4eda-4461-9b2e-f78a97646a8d","html_url":"https://github.com/powermobileweb/flask-login","commit_stats":null,"previous_names":["powermobileweb/flask-login"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powermobileweb%2Fflask-login","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powermobileweb%2Fflask-login/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powermobileweb%2Fflask-login/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powermobileweb%2Fflask-login/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/powermobileweb","download_url":"https://codeload.github.com/powermobileweb/flask-login/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231907790,"owners_count":18444187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","flask","login-system","python","session-management"],"created_at":"2024-12-30T19:58:08.006Z","updated_at":"2024-12-30T19:58:08.465Z","avatar_url":"https://github.com/powermobileweb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flask-Login\n\n[![build status](https://travis-ci.org/maxcountryman/flask-login.svg?branch=master)](https://travis-ci.org/maxcountryman/flask-login)\n[![coverage](https://coveralls.io/repos/maxcountryman/flask-login/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/maxcountryman/flask-login?branch=master)\n\nFlask-Login provides user session management for Flask. It handles the common\ntasks of logging in, logging out, and remembering your users' sessions over\nextended periods of time.\n\nFlask-Login is not bound to any particular database system or permissions\nmodel. The only requirement is that your user objects implement a few methods,\nand that you provide a callback to the extension capable of loading users from\ntheir ID.\n\n## Installation\n\nInstall the extension with pip:\n\n```sh\n$ pip install flask-login\n```\n\n## Usage\n\nOnce installed, the Flask-Login is easy to use. Let's walk through setting up\na basic application. Also please note that this is a very basic guide: we will\nbe taking shortcuts here that you should never take in a real application.\n\nTo begin we'll set up a Flask app:\n\n```python\nimport flask\n\napp = flask.Flask(__name__)\napp.secret_key = 'super secret string'  # Change this!\n```\n\nFlask-Login works via a login manager. To kick things off, we'll set up the\nlogin manager by instantiating it and telling it about our Flask app:\n\n```python\nimport flask_login\n\nlogin_manager = flask_login.LoginManager()\n\nlogin_manager.init_app(app)\n```\n\nTo keep things simple we're going to use a dictionary to represent a database\nof users. In a real application, this would be an actual persistence layer.\nHowever it's important to point out this is a feature of Flask-Login: it\ndoesn't care how your data is stored so long as you tell it how to retrieve it!\n\n```python\n# Our mock database.\nusers = {'foo@bar.tld': {'password': 'secret'}}\n```\n\nWe also need to tell Flask-Login how to load a user from a Flask request and\nfrom its session. To do this we need to define our user object, a\n`user_loader` callback, and a `request_loader` callback.\n\n```python\nclass User(flask_login.UserMixin):\n    pass\n\n\n@login_manager.user_loader\ndef user_loader(email):\n    if email not in users:\n        return\n\n    user = User()\n    user.id = email\n    return user\n\n\n@login_manager.request_loader\ndef request_loader(request):\n    email = request.form.get('email')\n    if email not in users:\n        return\n\n    user = User()\n    user.id = email\n\n    # DO NOT ever store passwords in plaintext and always compare password\n    # hashes using constant-time comparison!\n    user.is_authenticated = request.form['password'] == users[email]['password']\n\n    return user\n```\n\nNow we're ready to define our views. We can start with a login view, which will\npopulate the session with authentication bits. After that we can define a view\nthat requires authentication.\n\n```python\n@app.route('/login', methods=['GET', 'POST'])\ndef login():\n    if flask.request.method == 'GET':\n        return '''\n               \u003cform action='login' method='POST'\u003e\n                \u003cinput type='text' name='email' id='email' placeholder='email'/\u003e\n                \u003cinput type='password' name='password' id='password' placeholder='password'/\u003e\n                \u003cinput type='submit' name='submit'/\u003e\n               \u003c/form\u003e\n               '''\n\n    email = flask.request.form['email']\n    if flask.request.form['password'] == users[email]['password']:\n        user = User()\n        user.id = email\n        flask_login.login_user(user)\n        return flask.redirect(flask.url_for('protected'))\n\n    return 'Bad login'\n\n\n@app.route('/protected')\n@flask_login.login_required\ndef protected():\n    return 'Logged in as: ' + flask_login.current_user.id\n```\n\nFinally we can define a view to clear the session and log users out:\n\n```python\n@app.route('/logout')\ndef logout():\n    flask_login.logout_user()\n    return 'Logged out'\n```\n\nWe now have a basic working application that makes use of session-based\nauthentication. To round things off, we should provide a callback for login\nfailures:\n\n```python\n@login_manager.unauthorized_handler\ndef unauthorized_handler():\n    return 'Unauthorized'\n```\n\nComplete documentation for Flask-Login is available on [ReadTheDocs](https://flask-login.readthedocs.io/en/latest/).\n\n\n## Contributing\n\nWe welcome contributions! If you would like to hack on Flask-Login, please\nfollow these steps:\n\n1. Fork this repository\n2. Make your changes\n3. Install the requirements in `dev-requirements.txt`\n4. Submit a pull request after running `make check` (ensure it does not error!)\n\nPlease give us adequate time to review your submission. Thanks!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowermobileweb%2Fflask-login","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpowermobileweb%2Fflask-login","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowermobileweb%2Fflask-login/lists"}