Skip to content

jespino/anillo-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Anillo-Auth middleware

Build Status Coveralls Status Development Status Latest Version Supported Python versions License Downloads

Anillo auth is a middleware for authentication for the anillo nanoframework.

Backends

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.

Usage

Basic example

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)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages