caslib

CASServer

class caslib.CASServer(baseurl, opener=None)

Handle representing a CAS server

Parameters:
  • baseurl – The URL of the CAS server
  • opener (urllib2.OpenerDirector) – Optional custom opener (use this to do https certificate validation)
login(service, renew=False, gateway=None)

Generate a URL to log into a CASService.

>>> srv = CASServer('https://cas.example.org/cas')
>>> svc = type('CASService', (object,), dict(url='https://www.example.org/blah/login'))()
>>> srv.login(svc)
'https://cas.example.org/cas/login?service=https%3A%2F%2Fwww.example.org%2Fblah%2Flogin'
>>> srv.login(svc, gateway=True)
'https://cas.example.org/cas/login?gateway=true&service=https%3A%2F%2Fwww.example.org%2Fblah%2Flogin'
>>> srv.login(svc, renew=True)
'https://cas.example.org/cas/login?renew=true&service=https%3A%2F%2Fwww.example.org%2Fblah%2Flogin'
>>> srv.login(svc, gateway=True, renew=True)
AssertionError: Cannot use renew and gateway together
validate(service, ticket, renew=False)

Check with the CAS server to see if a service ticket is valid.

Parameters:
  • service (CASService) – The service being logged into. This should match the service the ticket was generated for.
  • ticket (string) – The ticket being validated.
  • renew (bool) – Option to assert that the user’s identity was revalidated for this ticket.
Returns:

the username associated with the ticket

Raises:

InvalidTicketError if the ticket is not valid

Be aware that CAS service tickets are not reusable. This prevents replay attacks.

CASService

class caslib.CASService(url)

Handle representing a CAS service

Parameter:url – The url of the service.
base(url)

Create a new CASService relocated to be under a different host+scheme+path

>>> svc = CASService('http://www.example.com/login')
>>> svc.url
'http://www.example.com/login'
>>> svc.base('http://www.example.com/test').url
'http://www.example.com/test/login'

InvalidTicketError

exception caslib.InvalidTicketError(ticket)

Bases: exceptions.ValueError

ticket
The invalid ticket

login_to_cas_service()

caslib.login_to_cas_service(url, username, password, opener=None)

Attempt to authenticate to a CAS /login form using the provided username and password.

Parameters:
  • url – the location of the login form
  • opener (urllib2.OpenerDirector) – Optional custom opener (use this to do https certificate validation). A urllib2.HTTPCookieProcessor, will be added if it does not already contain one.
Returns:

a file handle that can be read to see the result and a urllib2 opener with cookiejar

Raises:

CASLoginError if there was a problem parsing the login form or if username or password retrievel caused an exception

Raises:

urllib2.URLError if the form location or login result page could not be retrieved successfully

lxml.etree.HTMLParser will be used if it is available. Otherwise an XML parser choosen by xml.etree.cElementTree will be used.

CASLoginError

exception caslib.CASLoginError
Bases: exceptions.TypeError

Table Of Contents

Previous topic

Overview

Next topic

caslib.validating_https

This Page