gluu
公開メンバ関数 | 公開変数類 | 非公開メンバ関数 | 全メンバ一覧
oneid.OneID クラス
oneid.OneID 連携図
Collaboration graph

公開メンバ関数

def __init__ (self, server_flag="")
 
def set_credentials (self, api_id="", api_key="")
 
def validate (self, line)
 
def draw_signin_button (self, callback_url, attrs="", http_post=False)
 
def draw_quickfill_button (self, attrs)
 
def draw_provision_button (self, attrs)
 
def redirect (self, page, response, sessionid)
 
def success (self, response)
 
def save_session (self, response)
 
def get_session (self, sessionid)
 

公開変数類

 helper_server
 
 script_header
 
 oneid_form_script
 
 creds_file
 
 api_id
 
 api_key
 

非公開メンバ関数

def _call_helper (self, method, data={})
 
def _getnonce (self, response)
 

詳解

構築子と解体子

◆ __init__()

def oneid.OneID.__init__ (   self,
  server_flag = "" 
)
server_flag should be (for example) "-test" when using a non-production server
24  def __init__(self, server_flag=""):
25  """server_flag should be (for example) "-test" when using a non-production server"""
26  self.helper_server = "https://keychain%s.oneid.com" % server_flag
27  self.script_header = '<script src="https://api%s.oneid.com/js/includeexternal.js" type="text/javascript"></script>' % server_flag
28  self.oneid_form_script = '<script src="https://api%s.oneid.com/form/form.js" type="text/javascript"></script>' % server_flag
29  self.creds_file = "api_key"+server_flag+".json"
30  random.seed()
31 
32 

関数詳解

◆ _call_helper()

def oneid.OneID._call_helper (   self,
  method,
  data = {} 
)
private
Call the OneID Helper Service. 
33  def _call_helper(self, method, data={}):
34  """Call the OneID Helper Service. """
35  url = "%s/%s" % (self.helper_server, method)
36  r = requests.post(url, json.dumps(data), auth=(self.api_id, self.api_key))
37  return r.json
38 

◆ _getnonce()

def oneid.OneID._getnonce (   self,
  response 
)
private
Extract base64-encoded nonce from JWT in a response
140  def _getnonce(self, response):
141  """Extract base64-encoded nonce from JWT in a response"""
142  return response["nonces"]["repo"]["nonce"].split('.')[1]
143 
144 
145 
146 

◆ draw_provision_button()

def oneid.OneID.draw_provision_button (   self,
  attrs 
)
Create a provision button on the web page
97  def draw_provision_button(self, attrs):
98  """Create a provision button on the web page"""
99  js = "<div class='oneid_create_ctr'></div>"
100  js+= "<script type='text/javascript'>"
101  js+= "OneIdExtern.registerApiReadyFunction(function(){"
102  js+= "OneId.createOneIdButton('.oneid_create_ctr'," + json.dumps(attrs) +")"
103  js+= "})"
104  js+="</script>"
105 
106  return js
107 

◆ draw_quickfill_button()

def oneid.OneID.draw_quickfill_button (   self,
  attrs 
)
Create a OneID QuickFill button on the web page
86  def draw_quickfill_button(self, attrs):
87  """Create a OneID QuickFill button on the web page"""
88  js = "<span class='oneid_quickfill_ctr'></span>"
89  js+= "<script type='text/javascript'>"
90  js+= "OneIdExtern.registerApiReadyFunction(function(){"
91  js+= "OneId.accuFillButton('.oneid_quickfill_ctr'," + attrs +")"
92  js+= "})"
93  js+="</script>"
94 
95  return js
96 

◆ draw_signin_button()

def oneid.OneID.draw_signin_button (   self,
  callback_url,
  attrs = "",
  http_post = False 
)
Create a OneID Sign In button on the web page
67  def draw_signin_button(self, callback_url, attrs="", http_post=False):
68  """Create a OneID Sign In button on the web page"""
69  challenge = {"attr" : attrs,
70  'auth_level' : "OOB",
71  "callback" : callback_url}
72  if http_post:
73  challenge["request_method"] = "HTTP_POST"
74 
75  params = json.dumps({"challenge" : challenge })
76 
77  js = "<span class='oneid_login_ctr'></span>"
78  js+= "<script type='text/javascript'>"
79  js+= "OneIdExtern.registerApiReadyFunction(function(){"
80  js+= "OneId.loginButton('.oneid_login_ctr'," + params +")"
81  js+= "})"
82  js+="</script>"
83 
84  return js
85 

◆ get_session()

def oneid.OneID.get_session (   self,
  sessionid 
)
Retrieve attributes and session ID saved by validation page
131  def get_session(self, sessionid):
132  """Retrieve attributes and session ID saved by validation page"""
133  sessionfile = "/tmp/"+sessionid+".OneID"
134  f = open(sessionfile, "r")
135  data = f.read()
136  f.close()
137  os.remove(sessionfile)
138  return json.loads(data)
139 

◆ redirect()

def oneid.OneID.redirect (   self,
  page,
  response,
  sessionid 
)
Create the JSON string that instructs the AJAX code to redirect the browser to the account
108  def redirect(self, page, response, sessionid):
109  """Create the JSON string that instructs the AJAX code to redirect the browser to the account"""
110  if self.success(response):
111  suffix = "?sessionid="+sessionid
112  else:
113  suffix = ""
114 
115  return json.dumps({"error":response['error'],"errorcode":str(response['errorcode']),\
116  "url":page + suffix})
117 

◆ save_session()

def oneid.OneID.save_session (   self,
  response 
)
Save attributes and UID in a temporary file for account page
122  def save_session(self, response):
123  """Save attributes and UID in a temporary file for account page"""
124  sessionid = str(random.getrandbits(128))
125  sessionfile = "/tmp/"+sessionid+".OneID"
126  f = open(sessionfile, "w")
127  f.write(json.dumps({"uid":response["uid"], "attr":response["attr"]}))
128  f.close()
129  return sessionid;
130 

◆ set_credentials()

def oneid.OneID.set_credentials (   self,
  api_id = "",
  api_key = "" 
)
Set the credentials used for access to the OneID Helper Service
39  def set_credentials(self, api_id="", api_key=""):
40  """Set the credentials used for access to the OneID Helper Service"""
41  if api_id != "":
42  self.api_id = api_id
43  self.api_key = api_key
44  else:
45  f = open(self.creds_file,'r')
46  creds = json.loads(f.read())
47  f.close()
48  self.api_id = creds["API_ID"]
49  self.api_key = creds["API_KEY"]
50 

◆ success()

def oneid.OneID.success (   self,
  response 
)
Check errorcode in a response
118  def success(self, response):
119  """Check errorcode in a response"""
120  return response["errorcode"] == 0
121 

◆ validate()

def oneid.OneID.validate (   self,
  line 
)
Validate the data received by a callback
51  def validate(self,line):
52  """Validate the data received by a callback"""
53  resp = json.loads(line)
54  valdata = dict([("nonces",resp["nonces"]),("uid",resp["uid"])])
55  if "attr_claim_tokens" in resp:
56  valdata["attr_claim_tokens"] = resp["attr_claim_tokens"]
57  valresp = self._call_helper("validate",valdata)
58  if (not self.success(valresp)):
59  valresp["failed"] = "failed"
60  return valresp
61 
62  for x in valresp:
63  resp[x] = valresp[x]
64 
65  return resp
66 

メンバ詳解

◆ api_id

oneid.OneID.api_id

◆ api_key

oneid.OneID.api_key

◆ creds_file

oneid.OneID.creds_file

◆ helper_server

oneid.OneID.helper_server

◆ oneid_form_script

oneid.OneID.oneid_form_script

◆ script_header

oneid.OneID.script_header

このクラス詳解は次のファイルから抽出されました: