Extensible session based authentication and claims based authorization tool for CherryPy
Project description
Extensible session based authentication and claims based authorization tool for CherryPy.
Includes authentication controllers for default dispatcher and method dispatcher.
Default authentication controllers are provided in lribeiro.cherrypy.authorizer.authentication for default dispatcher and method dispatcher
cherrypy.authorizer is developed with Python3 and tested against Python2.7 and Python3.4
Example:
import cherrypy
from lribeiro.cherrypy import authorizer
from lribeiro.cherrypy.authorizer import authorize
from lribeiro.cherrypy.authorizer.authentication import Identity, AuthControllerDefaultDispatcher
# authenticator function signature can be whatever you'd like,
# as soon as you pass the correct parameters via Http POST
def _authenticator(username, password):
if username == 'user' and 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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d35b4266deb26a77274672899c4badc0fe8c308ac336edee0d16d1293196aa79 |
|
MD5 | 7a2cfb24aac9865a3422263e7a5c87fb |
|
BLAKE2b-256 | b9e1abfa0d462c66df3687ff05d1afbda5f07666c5b984da3661bbb2ef50dfa7 |
Close
Hashes for lribeiro.cherrypy.authorizer-1.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3340a1315833e18aaeb2a6f47c0e3969ad1a65b0310aea2379e997912fc11945 |
|
MD5 | b5d799ea5cb40004e71a660962784304 |
|
BLAKE2b-256 | 060e9875300788cd2362f7af5f2268ff6fc18c373be64df9f645fa66dcbba3a8 |