aiohttp-cas documentation

aiohttp-cas adds support for the Central Authentication Service protocol to your aiohttp.web thingamabob.

Example usage

from aiohttp import web
from aiohttp_session import setup as session_setup
from aiohttp_cas import login_required
from aiohttp_cas import setup as cas_setup

async def index(request):
    return web.Response(text='Hello!')

@login_required
async def secret(request):
    return web.Response(text='Shhh! Don\'t tell anyone!')

def make_app():
    app = web.Application()
    # Set up aiohttp_session however you like
    cas_setup(app, 'your_cas_host_here', 'your_cas_version_here')
    app.router.add_route('GET', '/', index)
    app.router.add_route('GET', '/secret', secret)
    return app

web.run_app(make_app())

Functions

aiohttp_cas.setup(app, host, version, host_prefix='', host_scheme='https', login_route='/login', logout_route='/logout', on_success='/', on_logout='/')

Sets up CAS authentication for the app.

Parameters:
  • app – aiohttp app.
  • host (str) – CAS host to authenticate against
  • version (str) – Version of CAS to use
  • host_prefix (str) – Server prefix that CAS runs under
  • host_scheme (str) – Scheme to access the CAS host under
  • login_route (str) – Route for local login handler
  • logout_route (str) – Route for local logout handler
  • on_success (str) – Default route for redirect after a successful login
  • on_logout (str) – Route for redirect after logout
aiohttp_cas.login_required(func, *args, **kwargs)

Decorator for handler functions.

Applied to a request handler, it will first check if our user is logged in, and if they are not, will tack on a redirect parameter to the session set to the requested url and run the login handler

Parameters:func – function to wrap