Authentication library for Flask Web Framework
Project description
Flask-Authlib
Flask-Authlib - authentication library for Flask Web Framework.
- Templates: login , register
- User Model
- View Functions
Install
By using pip
:
$ pip install flask-authlib
Usage
- Firstly, import
Flask
fromflask
- Secondly, import
SQLAlchemy
fromflask_sqlalchemy
- Lastly, import
Auth
fromflask_authlib
Code:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_authlib import Auth
Define your app
and db
. Create auth var from Auth
class and call init()
method:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_authlib import Auth
app = Flask(__name__)
db = SQLAlchemy(app)
auth = Auth(app=app, db=db)
auth.init()
# simple route
@app.route('/')
def home_page():
return {'message': 'Hi, bro 😁'}
Run your backend:
$ export FLASK_APP=<app> && export FLASK_ENV=development
$ flask run --reload
Screenshot:
Login page at /login
Register page at /register
Advanced Usage
You can change urls
Defaults
- Login page -
/login
- Register page -
/register
- Logout url -
/logout
- Home page -
/
Write your urls before calling init()
method at Auth
class:
...
auth = Auth(app=app, db=db, login_url='/mylogin',
register_url='/myreg', logout_url='/myexit',
home_page='/')
auth.init()
...
You can set your own template config!
You can change:
- Button colors at login and register page
- Title at login and register page
- All labels like Username.. email ...
- Text in button.
Default template config
config = {
"LOGIN_BTN": "btn-success",
"REGISTER_BTN": "btn-warning",
"LOGIN_BTN_TEXT": "Login",
"REGISTER_BTN_TEXT": "Register",
"LOGIN_PAGE_TITLE": "Login",
"REGISTER_PAGE_TITLE": "Register",
"LOGIN_LABEL_USERNAME": "Username",
"LOGIN_LABEL_PASSWORD": "Password",
"REGISTER_LABEL_USERNAME": "Username",
"REGISTER_LABEL_PASSWORD": "Password",
"REGISTER_LABEL_EMAIL": "Email address"
}
p.s login-btn colors based on bootstrap classes
...
my_config = {
"LOGIN_BTN": "btn-danger",
"REGISTER_BTN": "btn-primary",
"LOGIN_PAGE_TITLE": "Admin",
"REGISTER_PAGE_TITLE": "Admin"
}
auth = Auth(app=app, db=db, template_config=my_config)
auth.init()
...
p.s if the some settings are not entered, they will remain in their state.
Screenshot:
Login page with own config
Register page with own config
Author: Abduaziz Ziyodov
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Flask-Authlib-1.2.0.tar.gz
.
File metadata
- Download URL: Flask-Authlib-1.2.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8dc1293a1ac7e9c95de2bd472b3c2733cbd49bc91af011534234c04ae199f8d |
|
MD5 | 0be7e7ac3f7b3e0c69450df6b1b09253 |
|
BLAKE2b-256 | 300591767c66a116ea6f6745264cb5c759227f1bad1f52c150eccb2ec7eb7600 |
File details
Details for the file Flask_Authlib-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: Flask_Authlib-1.2.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f62de69e45d00e4a3ea3821273bbcc4b30d8e7f08f0792be8857969d1ca1253 |
|
MD5 | c7b8e7494db61ff117ba3b8d6ca3da96 |
|
BLAKE2b-256 | e9b67aa25153fd9393e62ba2d44a9bf05758e7644d40a8d3e5678a62a5ae4723 |