Authentication library for Flask Web Framework
Project description
Flask-Authlib 🔐
Flask-Authlib - authentication library for Flask Web Framework.
Advantages:
- Templates: login , register
- Default
user
Model - View Functions
Install
By using pip
:
$ pip install flask-authlib
Simple Usage
- Import
Flask
fromflask
- Import
SQLAlchemy
fromflask_sqlalchemy
- Import
Auth
fromflask_authlib
Code Sample:
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
Screenshots:
Login page at /login
Register page at /register
Advanced Usage
You can change urls
Defaults
- Home page -
/
- Login page -
/login
- Register page -
/register
- Logout url -
/logout
Write your urls before calling init()
method:
...
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 color on forms
- Form 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 btn colors based on bootstrap classes
Setting your config:
...
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()
...
If some settings are not entered, they remain as default
Screenshots:
Login page
Register page
Running Example 🚀
First way
Required
docker
Project directory have:
- dockerfile
- docker_compose.yml
For running this you have to type this command:
$ docker-compose up
Screenshot:
Second way
Clone this repo:
$ git clone https://github.com/AbduazizZiyodov/flask-authlib.git
Navigate to /example
:
$ cd example/
Install all required packages:
$ pip install -r requirements.txt
Run development server:
$ python app.py
or$ gunicorn app:app
or$ export FLASK_APP=app && flask run --reload
Enjoy 😅
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.3.1.tar.gz
.
File metadata
- Download URL: Flask-Authlib-1.3.1.tar.gz
- Upload date:
- Size: 9.8 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 | d671624e70321c4f1484c85571b72eb211310aa269c226e52453ec901d1e4044 |
|
MD5 | d2354d63695660ef60a7004052ed7caa |
|
BLAKE2b-256 | 3813a8fd9b2d7aa2e289d57293a1e7ab0ef2ff39e5c67d13902b4da57c66b59f |
File details
Details for the file Flask_Authlib-1.3.1-py3-none-any.whl
.
File metadata
- Download URL: Flask_Authlib-1.3.1-py3-none-any.whl
- Upload date:
- Size: 11.5 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 | 1b93e27259898b687bfacee1a1cc8a954f240f4ed0c6f61ece08def87ea6cc66 |
|
MD5 | 7f77494f9712ac1ca4cd64e2f780a64c |
|
BLAKE2b-256 | 2934a3c3af7f4dda0c9448d3162e40d65debc75038ebb389db7ca59353bc3456 |