Sanic-Auth - Simple Authentication for Sanic
Sanic-Auth implements a minimal backend agnostic session-based user authentication mechanism for Sanic.
Quick Start
Installation
pip install --upgrade Sanic-Auth
How to use it
from sanic_auth import Auth
from sanic import Sanic, response
app = Sanic(__name__)
app.config.AUTH_LOGIN_ENDPOINT = 'login'
@app.middleware('request')
async def add_session_to_request(request):
# setup session
auth = Auth(app)
@app.route('/login', methods=['GET', 'POST'])
async def login(request):
message = ''
if request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
# fetch user from database
user = some_datastore.get(name=username)
if user and user.check_password(password):
auth.login_user(request, user)
return response.redirect('/profile')
return response.html(HTML_LOGIN_FORM)
@app.route('/logout')
@auth.login_required
async def logout(request):
auth.logout_user(request)
return response.redirect('/login')
@app.route('/profile')
@auth.login_required(user_keyword='user')
async def profile(request, user):
return response.json({'user': user})
For more details, please see documentation.
License
BSD New, see LICENSE for details.
Links
Metadata
Release files for Sanic-Auth 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| Sanic-Auth-0.3.0.tar.gz | 11.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Sanic_Auth-0.3.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 17.0 kB
Release files / Sanic-Auth-0.3.0.tar.gz
| Download URL | Sanic-Auth-0.3.0.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
280534eba4bbd063b5854450ad6d27f8be7f905ce981e9f7e3586589ad278235
|
|
BLAKE2b-256 checksum How to use checksums |
29eaf615954b5c48c01d031e3c3fdae37b3ed58176cff123c659573ea461aaea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.7rc1
|
Release files / Sanic_Auth-0.3.0-py2.py3-none-any.whl
| Download URL | Sanic_Auth-0.3.0-py2.py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
6f7783b86aee36c95faea44f47e43455a61bb1609248e8ed75df62266aa70c18
|
|
BLAKE2b-256 checksum How to use checksums |
5e74d15c158c18ac0a24f2c6a0ef7387b27b39de374fe2235b51e4f5ba2c0457
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.7rc1
|
Security for Sanic-Auth 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.