-
Notifications
You must be signed in to change notification settings - Fork 6
/
cvl_shib_auth.py
47 lines (38 loc) · 1.51 KB
/
cvl_shib_auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
import wx
import cvlsshutils.RequestsSessionSingleton
import cvlsshutils.AAF_Auth
import json
class shibbolethDance():
def __init__(self,pubkey,parent,*args,**kwargs):
self.pubkey=pubkey
self.parent=parent
if kwargs.has_key('idp'):
self.idp=kwargs['idp']
else:
self.idp=None
def postKey(self,url):
data={}
data['ssh_pub_key']=self.pubkey
r=self.session.post(url,data=data,verify=False)
if r.status_code==200:
if 'json' in r.headers['content-type']:
returned=json.loads(r.text)
if isinstance(returned,type({})):
self.__dict__.update(returned)
if r.status_code!=200:
raise Exception("%s"%r.text)
def getIdP(self):
return self.idp
def getUsername(self):
if hasattr(self,'username'):
return self.username
else:
raise Exception('Username not set by the cvl_shib_auth module. (It really should have been)')
def copyID(self):
# Use of a singleton here means that we should be able to do SSO on any AAF/Shibolleth web service. However we might have to guess the IdP.
self.session=cvlsshutils.RequestsSessionSingleton.RequestsSessionSingleton().GetSession()
destURL="https://118.138.241.242/cvl/"
auth=cvlsshutils.AAF_Auth.AAF_Auth(self.session,destURL,parent=self.parent,idp=self.idp)
self.idp=auth.getIdP()
self.postKey(destURL)