Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pyx/sanic-auth
Sanic-Auth - Simple Authentication for Sanic
https://github.com/pyx/sanic-auth
authentication sanic
Last synced: about 1 month ago
JSON representation
Sanic-Auth - Simple Authentication for Sanic
- Host: GitHub
- URL: https://github.com/pyx/sanic-auth
- Owner: pyx
- License: other
- Created: 2017-05-17T05:38:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-20T22:53:31.000Z (about 1 year ago)
- Last Synced: 2024-09-24T13:36:21.972Z (3 months ago)
- Topics: authentication, sanic
- Language: Python
- Size: 39.1 KB
- Stars: 54
- Watchers: 3
- Forks: 12
- Open Issues: 5
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
- awesome-sanic - Sanic-Auth - session can work togather). (Extensions / Authentication)
README
============================================
Sanic-Auth - Simple Authentication for Sanic
============================================Sanic-Auth implements a minimal backend agnostic session-based user
authentication mechanism for `Sanic`_... _Sanic: https://github.com/channelcat/sanic
Quick Start
===========Installation
------------.. code-block:: sh
pip install --upgrade Sanic-Auth
How to use it
-------------.. code-block:: python
from sanic_auth import Auth
from sanic import Sanic, responseapp = Sanic(__name__)
app.config.AUTH_LOGIN_ENDPOINT = 'login'@app.middleware('request')
async def add_session_to_request(request):
# setup sessionauth = 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
=====- `Documentation `_
- `Issue Tracker `_
- `Source Package @ PyPI `_
- `Git Repository @ Github
`_- `Git Repository @ Gitlab
`_- `Development Version
`_