Provide an easy way to handle authentication(login with jwt generated, token required decorator) in flask applications
Project description
JWT Flask Authentication
This package provide an easy way to handle authentication in a flask application. By now it manages login and token required constraint.
How to use
You must have a user class defined like this:
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import check_password_hash
db = SQLAlchemy()
class User(db.Model):
...
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(255))
password = db.Column(db.String(255))
...
def validate_password(self, password):
return check_password_hash(self.password, password)
...
Then instanciate the Auth class and decorate view functions:
from jwt_flask_auth import Auth
from flask import Flask
from models import User
app = Flask(__name__)
auth = Auth(
user_class=User,
user_id_field='id',
username_field='username',
password_field='password',
)
@app.route('/login', methods=['POST'])
def login():
return auth.login()
@app.route('/protected')
@auth.token_required
def protected_route():
return 'You have access'
Login will generate a token with a payload containing the user_id, username, and the expiration.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jwt_flask_ext-0.0.2.tar.gz
(2.9 kB
view details)
File details
Details for the file jwt_flask_ext-0.0.2.tar.gz.
File metadata
- Download URL: jwt_flask_ext-0.0.2.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17046497ee2a5fc56e94cc4ec26a4b39d1ae0e7395c9f2572a35cc8cd0d4a8af
|
|
| MD5 |
c9bebbf2bb5c71b50473f0bdafe8da27
|
|
| BLAKE2b-256 |
77a52a239115cd66e27b62f9feed1f83c1ff31b79c2361a7166d406e8b69edfa
|