Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit 03ccfe5

Browse files
Expand README.
1 parent 84fabb6 commit 03ccfe5

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

README.rst

+61-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
python-cas-client
22
=================
33

4-
A python CAS client
4+
A Python CAS (Central Authentication Service) client for interfacing with a CAS
5+
service implementation, such as https://github.com/rbCAS/CASino or
6+
https://github.com/apereo/cas.
7+
8+
This project provides tools for building well-formed CAS-related URLs, parsing
9+
CAS XML payloads and managing the server-side session stores necessary for
10+
handling SLO (single logout).
511

612
Installation
713
------------
@@ -18,6 +24,60 @@ Supports Python 2.7 and 3.4.
1824
Testing
1925
-------
2026

27+
``cas_client`` uses ``tox`` to run its unit tests under Python 2.7 and 3.4.
28+
2129
::
2230

2331
python-cas-client$ tox
32+
33+
Example
34+
-------
35+
36+
The following un-tested pseudo-code shows how you might use ``cas_client`` in a
37+
Flask project.
38+
39+
::
40+
41+
from cas_client import CASClient
42+
from flask import Flask, redirect, request, session, url_for
43+
44+
app = Flask(__name__)
45+
46+
app_login_url = 'http://www.my-app.com/login'
47+
cas_url = 'http://cas.my-app.com'
48+
cas_client = CASClient(cas_url, auth_prefix='')
49+
50+
@app.route('/login')
51+
def login():
52+
ticket = request.args.get('ticket')
53+
if ticket:
54+
try:
55+
cas_response = cas_client.perform_service_validate(
56+
ticket=ticket,
57+
service_url=app_login_url,
58+
)
59+
except:
60+
# CAS server is currently broken, try again later.
61+
return redirect(url_for('root'))
62+
if cas_response and cas_response.success:
63+
session['logged-in'] = True
64+
return redirect(url_for('root'))
65+
del(session['logged-in'])
66+
cas_login_url = cas_client.get_login_url(service_url=app_login_url)
67+
return redirect(cas_login_url)
68+
69+
@app.route('/logout')
70+
def logout():
71+
del(session['logged-in'])
72+
cas_logout_url = cas_client.get_logout_url(service_url=app_login_url)
73+
return redirect(cas_logout_url)
74+
75+
@app.route('/')
76+
def root():
77+
if session.get('logged-in'):
78+
return 'You Are Logged In'
79+
else:
80+
return 'You Are Not Logged In'
81+
82+
This pseudo-code does not handle server-side session stores or single logout,
83+
only the bare minimum for standard login and logout.

cas_client/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version_info__ = (0, 1, 0)
1+
__version_info__ = (0, 1, 1)
22
__version__ = '.'.join(str(_) for _ in __version_info__)

0 commit comments

Comments
 (0)