Skip to main content

Authentication library for Flask Web Framework

Project description

Flask-Authlib 🔐

PyPI version


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 from flask
  • Import SQLAlchemy from flask_sqlalchemy
  • Import Auth from flask_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 Login page at /login

REGISTER 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 Login page


REGISTER 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:

DOCKER

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

Flask-Authlib-1.3.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

Flask_Authlib-1.3.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file Flask-Authlib-1.3.0.tar.gz.

File metadata

  • Download URL: Flask-Authlib-1.3.0.tar.gz
  • Upload date:
  • Size: 8.6 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

Hashes for Flask-Authlib-1.3.0.tar.gz
Algorithm Hash digest
SHA256 ac5b52fc5c00e812d0f26c6b128b70b8c65a521b23d5ebd936456fb7f193ba53
MD5 3c4217222d9c810b820197ae6f4bc1bb
BLAKE2b-256 7171be49e0d4be7722c4f8a218aa3862240bde4b7b3adc4da4515704d05db238

See more details on using hashes here.

File details

Details for the file Flask_Authlib-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: Flask_Authlib-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 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

Hashes for Flask_Authlib-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebe6760b26709a55f815e138ac8492f500b0e122a2664b31363a410ff1eda67f
MD5 20c69e583c8f21e9877073ae62a1186d
BLAKE2b-256 201238453bb1f57e80a649b5c672cbd05fe5fbbd98029a7e5005361af5fb81b2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page