I'm using gluon/contrib/login_methods/cas_auth.py to authenticate against
our campus CAS server. Our server returns most of the interesting values
nested within a single "cas:attributes" node, which is not parsed by
cas_auth.py. I modified cas_auth.py (starting around line 110) to pull all
"cas:" subnodes into the "res" structure, ignoring the three spurious ones
(see below). It seems to work, but I'm wondering if there is a more direct
way to achieve the same thing.
Tim
import xml.parsers.expat as expat
res = dict()
def start_element(name, attrs):
global key
if name.startswith('cas:'):
key = name[4:].encode('utf8')
def char_data(value):
global key
if key in ['attributes', 'serviceResponse',
'authenticationSuccess']:
return
if key in res:
if isinstance(res[key], list):
res[key].append(value)
else:
res[key] = [res[key], value]
else:
res[key] = value
parser = expat.ParserCreate()
parser.StartElementHandler = start_element
parser.CharacterDataHandler = char_data
try:
parser.Parse(data)
return res
except expat.ExpatError: pass
return None # fallback