Anillo auth is a middleware for authentication for the anillo nanoframework.
Anillo auth comes with some backends for different types of authentication, thats allow you to define your own authentication backend, or reuse one of the anillo-auth shipped backends.
The currently working backends are:
- HttpBasicAuthBackend: Based on the http basic auth headers.
- SessionBackend: Based on the session identity key.
- JWSBackend: Based on the Authentication header and using the Json Web Signature format.
from anillo.app import application
from anillo.handlers.routing import router, url
from anillo.middlewares.cookies import wrap_cookies
from anillo.middlewares.session import wrap_session, MemoryStorage
from anillo.http import Ok
from anillo.utils.common import chain
from anillo_auth.auth import wrap_auth
from anillo_auth.backends.session import SessionBackend
import json
def index(request):
return Ok(json.dumps(request.get('session', {}).get('identity')))
def login(request):
request.session['identity'] = {"user_id": 1}
return Ok("logged-in")
urls = [
url("/", index),
url("/login", login),
]
app = application(chain(
wrap_cookies,
wrap_session(storage=MemoryStorage),
wrap_auth(backend=SessionBackend),
router(urls)
))
if __name__ == '__main__':
from anillo import serving
serving.run_simple(app, port=5000)