Skip to main content

A Python CAS client

Project description

A Python CAS (Central Authentication Service) client for interfacing with a CAS service implementation, such as https://github.com/rbCAS/CASino or https://github.com/apereo/cas.

This project provides tools for building well-formed CAS-related URLs, parsing CAS XML payloads and managing the server-side session stores necessary for handling SLO (single logout).

Installation

Supports Python 2.7 and 3.4.

$ git clone git@github.com:discogs/python-cas-client.git
$ cd python-cas-client
python-cas-client$ pip install .
...

Testing

cas_client uses tox to run its unit tests under Python 2.7 and 3.4.

python-cas-client$ tox

Example

The following un-tested pseudo-code shows how you might use cas_client in a Flask project.

from cas_client import CASClient
from flask import Flask, redirect, request, session, url_for

app = Flask(__name__)

app_login_url = 'http://www.my-app.com/login'
cas_url = 'http://cas.my-app.com'
cas_client = CASClient(cas_url, auth_prefix='')

@app.route('/login')
def login():
    ticket = request.args.get('ticket')
    if ticket:
        try:
            cas_response = cas_client.perform_service_validate(
                ticket=ticket,
                service_url=app_login_url,
                )
        except:
            # CAS server is currently broken, try again later.
            return redirect(url_for('root'))
        if cas_response and cas_response.success:
            session['logged-in'] = True
            return redirect(url_for('root'))
    del(session['logged-in'])
    cas_login_url = cas_client.get_login_url(service_url=app_login_url)
    return redirect(cas_login_url)

@app.route('/logout')
def logout():
    del(session['logged-in'])
    cas_logout_url = cas_client.get_logout_url(service_url=app_login_url)
    return redirect(cas_logout_url)

@app.route('/')
def root():
    if session.get('logged-in'):
        return 'You Are Logged In'
    else:
        return 'You Are Not Logged In'

This pseudo-code does not handle server-side session stores or single logout, only the bare minimum for standard login and logout.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cas_client-1.0.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

cas_client-1.0.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file cas_client-1.0.0.tar.gz.

File metadata

  • Download URL: cas_client-1.0.0.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for cas_client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8c881fa023ff2b8f8879b314aaa32bf9c79de695cb438a50dc4ee25dfc3fc08b
MD5 be64f4b772387f5be169566e5be70044
BLAKE2b-256 6583a8467cd819114cb242081fef12b88ca6bab0b9e92e5882c9bac0e0fa1e24

See more details on using hashes here.

File details

Details for the file cas_client-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cas_client-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for cas_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6dec881b311467bd64abef1e7974d45ab29feda3de56a3ba50c44b2984ccbea
MD5 d287224378cf00a46d03bc1711ac6273
BLAKE2b-256 a3c2018ded9cd48e1c4e976947f10f2bfca2c16041f98faf02e1dfbe9fbfaaea

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page