{"id":15297470,"url":"https://github.com/okorienev/flask-jwtlogin","last_synced_at":"2026-01-06T06:05:29.078Z","repository":{"id":57430437,"uuid":"136595382","full_name":"okorienev/flask-jwtlogin","owner":"okorienev","description":"flask extension to handle user login in APIs","archived":false,"fork":false,"pushed_at":"2018-07-09T15:53:00.000Z","size":23,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-05T04:36:34.004Z","etag":null,"topics":["flask-extensions","jwt-authentication","python-3"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/okorienev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-08T09:09:37.000Z","updated_at":"2020-12-14T12:58:57.000Z","dependencies_parsed_at":"2022-08-26T03:51:10.743Z","dependency_job_id":null,"html_url":"https://github.com/okorienev/flask-jwtlogin","commit_stats":null,"previous_names":["alexpraefectus/flask-jwtlogin"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okorienev%2Fflask-jwtlogin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okorienev%2Fflask-jwtlogin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okorienev%2Fflask-jwtlogin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okorienev%2Fflask-jwtlogin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/okorienev","download_url":"https://codeload.github.com/okorienev/flask-jwtlogin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245467615,"owners_count":20620216,"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":["flask-extensions","jwt-authentication","python-3"],"created_at":"2024-09-30T19:17:46.492Z","updated_at":"2026-01-06T06:05:29.053Z","avatar_url":"https://github.com/okorienev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flask-jwtlogin quickstart\nflask-jwtlogin is a lightweight flask extension to handle users in REST APIs  \nWhat it offers to you:\n* **jwt_required** decorator to check jwt presence in current request\n* **generate_jwt** func to get token with user identifier encrypted\n* **load_user** for manual loading user from request using callback function\n* **current_user** proxy \n\n### How to use it?\nflask-jwtlogin can be simply installed with pip:\n```bash\npip install flask-jwtlogin\n```\nFirst of all, you need some configuration:\n```python\n{\n    'JWT_HEADER_NAME': 'your_header_name',  #header to retrieve token from request\n    'JWT_SECRET_KEY': 'you will never guess me',  #keep it secret\n    'JWT_ENCODING_ALGORITHM': 'HS256',  #look at algorithms present in PyJWT\n    'JWT_LIFETIME': 3600 * 24 * 7  # in seconds\n}\n```\nThen create a login manager instance.\n```python\nlogin_manager = jwtl.JWTLogin()  #creating instance\nlogin_manager.init_app(app)  #importing configuration\n```\n\nYou need to set callback function loading users from your storage and to inherit your user class from KnownUser\n```python\nclass User(jwtl.KnownUser):\n    \"\"\"Example of class representing user\"\"\"\n    def __init__(self, name, age, identifier):\n        self.name = name\n        self.age = age\n        self.identifier = identifier\n        \nuser_storage = [  #sample storage\n    User(\"Tom\", 22, \"AF5F123\"),\n    User(\"Jim\", 25, \"FFF1832\"),\n    User(\"Peter\", 18, \"CB0CA931\")]\n\n\n@login_manager.user_loader\ndef load_user(identifier):\n    \"\"\"example of user loader function\"\"\"\n    for i in user_storage:\n        if i.identifier == identifier:\n            return i\n```\n\nSample route to generate user tokens: \n```python\n@app.route('/get-token/\u003cname\u003e')\ndef get_token(name):\n    \"\"\"Sample view that returns jwt\"\"\"\n    for i in user_storage:\n        if i.name == name:\n            return jsonify(login_manager.generate_jwt_token(i.identifier))  \n    abort(401)\n```\n\nSample route to load user:\n```python\n@app.route('/login/')\n@login_manager.jwt_required\ndef login():\n    \"\"\"View that loads user from jwt present in request\"\"\"\n    user = login_manager.load_user()\n    return user.identifier\n```\n\nthe example above shows the way of manual user loading but module also provides suitable proxy\nThe **jwt_required** decorator adds user loaded from request to **flask.g** and **current_user** loads it.  \n```python\n@app.route('/current_user_test/')\n@login_manager.jwt_required\ndef test_current_user():\n    return jwtl.current_user.identifier\n```\nflask.g lives inside application context (new for each request) so it's safe to store values in API there \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fokorienev%2Fflask-jwtlogin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fokorienev%2Fflask-jwtlogin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fokorienev%2Fflask-jwtlogin/lists"}