Basic Usage of Library
Flask-Authlib
uses SQLAlchemy
(sqlalchemy extension for flask) for the database part. After installation this ORM, you should import AuthManager
and use it like this:
1 2 3 |
|
Define your Flask application
, db
and AuthManager
base object:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
flask_authlib.AuthManager
AuthManager
takes two arguments(required): app
(Flask App) and db
(SQLAlchemy).
Add a simple route and protect it by flask login's login_required
decorator for testing login functionality:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
If we try to navigate
/protected
, it should navigate us to the login page. That is why we used flask_login's@login_required
.
Next, run your flask application and you will see magic
things 😂 (navigate to protected route):
-
Login Page
-
Register Page Tada 🎉
If we look our application's directory, we can see new folders which are created by flask_authlib
:
-
static/
- stores static files (js
,css
,fonts
... ) -
templates/
- stores*.html
files