Extensible session based authentication and claims based authorization tool for CherryPy
Project description
===================
cherrypy-authorizer
===================
Extensible session based authentication and claims based authorization tool for CherryPy.
Includes authentication controllers for default dispatcher and method dispatcher.
Currently only supports Python 3
Example:
--------
.. sourcecode:: python
import cherrypy
from lribeiro.cherrypy import authorizer
from lribeiro.cherrypy.authorizer import authorize
from lribeiro.cherrypy.authorizer.authentication import Identity, AuthControllerDefaultDispatcher
def _authenticator(**credentials):
if credentials['username'] == 'user' and credentials['password'] == 'pass':
return Identity('id', 'user')
def _authorizer(claims):
if 'read' in claims and claims['read'] == 'page':
return True
if 'write' in claims and claims['write'] == 'page':
return True
return False
class Area1:
@cherrypy.expose
@authorize({'read': 'page'})
def index(self):
return 'authorized'
@authorize
class Area2:
@cherrypy.expose
def index(self):
return 'authorized'
@cherrypy.expose
@authorize({'write': 'site'})
def restricted(self):
return 'restricted'
class Root:
@cherrypy.expose
def index(self):
pass
@cherrypy.expose
def process_login(self, username, password):
try:
authenticate(username=username, password=password)
raise cherrypy.HTTPRedirect('/area1')
except AuthenticationError:
raise cherrypy.HTTPError(403)
if __name__ == '__main__':
conf = {
'/': {
'tools.sessions.on': True,
'tools.authorizer.on': True,
'auth.authenticator': _authenticator,
'auth.authorizer': _authorizer,
'auth.login_page': '/login',
'auth.login_redirect': '/logged_in',
'auth.logout_redirect': '/logged_out',
'auth.unauthorized_redirect': '/unauthorized'
}
}
root = Root()
root.area1 = Area1()
root.area2 = Area2()
root.auth = AuthControllerDefaultDispatcher()
cherrypy.quickstart(root, '/', conf)
cherrypy-authorizer
===================
Extensible session based authentication and claims based authorization tool for CherryPy.
Includes authentication controllers for default dispatcher and method dispatcher.
Currently only supports Python 3
Example:
--------
.. sourcecode:: python
import cherrypy
from lribeiro.cherrypy import authorizer
from lribeiro.cherrypy.authorizer import authorize
from lribeiro.cherrypy.authorizer.authentication import Identity, AuthControllerDefaultDispatcher
def _authenticator(**credentials):
if credentials['username'] == 'user' and credentials['password'] == 'pass':
return Identity('id', 'user')
def _authorizer(claims):
if 'read' in claims and claims['read'] == 'page':
return True
if 'write' in claims and claims['write'] == 'page':
return True
return False
class Area1:
@cherrypy.expose
@authorize({'read': 'page'})
def index(self):
return 'authorized'
@authorize
class Area2:
@cherrypy.expose
def index(self):
return 'authorized'
@cherrypy.expose
@authorize({'write': 'site'})
def restricted(self):
return 'restricted'
class Root:
@cherrypy.expose
def index(self):
pass
@cherrypy.expose
def process_login(self, username, password):
try:
authenticate(username=username, password=password)
raise cherrypy.HTTPRedirect('/area1')
except AuthenticationError:
raise cherrypy.HTTPError(403)
if __name__ == '__main__':
conf = {
'/': {
'tools.sessions.on': True,
'tools.authorizer.on': True,
'auth.authenticator': _authenticator,
'auth.authorizer': _authorizer,
'auth.login_page': '/login',
'auth.login_redirect': '/logged_in',
'auth.logout_redirect': '/logged_out',
'auth.unauthorized_redirect': '/unauthorized'
}
}
root = Root()
root.area1 = Area1()
root.area2 = Area2()
root.auth = AuthControllerDefaultDispatcher()
cherrypy.quickstart(root, '/', conf)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for lribeiro.cherrypy.authorizer-1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76de37f43e66cbc680d936598ec0bf25a5034505e14fa9289960d042eeb4046e |
|
MD5 | 4f3e27940aea42541f230e16f584d4f3 |
|
BLAKE2b-256 | a8eae415482822de13c754ca7da4cfde71540e6adf44faa0e364b5f7bca85215 |
Close
Hashes for lribeiro.cherrypy.authorizer-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7946eed298a30f75ea13ca8a95318315b7af94628ee008f04297740845d6b5db |
|
MD5 | 20666fbb1c38159847a06b5a7a8e5c97 |
|
BLAKE2b-256 | 21b99d483aa6177ffb1dadb2fbd2ffd80dd5a919b61e044c4e461adbb18a713c |