本文整理汇总了Python中gluon.tools.fetch方法的典型用法代码示例。如果您正苦于以下问题:Python tools.fetch方法的具体用法?Python tools.fetch怎么用?Python tools.fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gluon.tools
的用法示例。
在下文中一共展示了tools.fetch方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_user
# 需要导入模块: from gluon import tools [as 别名]
# 或者: from gluon.tools import fetch [as 别名]
def get_user(self):
request = self.request
if request.vars.token:
user = Storage()
data = urllib.urlencode(
dict(apiKey=self.api_key, token=request.vars.token))
auth_info_json = fetch(self.auth_url + '?' + data)
auth_info = json.loads(auth_info_json)
if auth_info['stat'] == 'ok':
self.profile = auth_info['profile']
provider = re.sub('[^\w\-]', '', self.profile['providerName'])
user = self.mappings.get(
provider, self.mappings.default)(self.profile)
return user
elif self.on_login_failure:
redirect(self.on_login_failure)
return None
示例2: get_user
# 需要导入模块: from gluon import tools [as 别名]
# 或者: from gluon.tools import fetch [as 别名]
def get_user(self):
request = self.request
user = None
if request.vars.token:
try:
auth_url = self.auth_base_url + self.api_secret + "/" + request.vars.token
json_data = fetch(auth_url, headers={'User-Agent': "LoginRadius - Python - SDK"})
self.profile = json.loads(json_data)
provider = self.profile['Provider']
mapping = self.mappings.get(provider, self.mappings['default'])
user = mapping(self.profile)
except (ValueError, KeyError):
pass
if user is None and self.on_login_failure:
redirect(self.on_login_failure)
return user
示例3: get_user
# 需要导入模块: from gluon import tools [as 别名]
# 或者: from gluon.tools import fetch [as 别名]
def get_user(self):
request = self.request
if request.vars.assertion:
audience = self.audience
issuer = self.issuer
assertion = XML(request.vars.assertion, sanitize=True)
verify_data = {'assertion': assertion, 'audience': audience}
auth_info_json = fetch(self.verify_url, data=verify_data)
j = json.loads(auth_info_json)
epoch_time = int(time.time() * 1000) # we need 13 digit epoch time
if j["status"] == "okay" and j["audience"] == audience and j['issuer'].endswith(issuer) and j['expires'] >= epoch_time:
return dict(email=j['email'])
elif self.on_login_failure:
#print "status: ", j["status"]=="okay", j["status"]
#print "audience:", j["audience"]==audience, j["audience"], audience
#print "issuer: ", j["issuer"]==issuer, j["issuer"], issuer
#print "expires: ", j["expires"] >= epoch_time, j["expires"], epoch_time
redirect(self.on_login_failure)
else:
redirect('https://login.persona.org')
return None
示例4: get_user
# 需要导入模块: from gluon import tools [as 别名]
# 或者: from gluon.tools import fetch [as 别名]
def get_user(self):
request = self.request
user = None
if request.vars.connection_token:
auth_url = "https://%s.api.oneall.com/connections/%s.json" % \
(self.domain, request.vars.connection_token)
auth_pw = "%s:%s" % (self.public_key,self.private_key)
auth_pw = base64.b64encode(auth_pw)
headers = dict(Authorization="Basic %s" % auth_pw)
try:
auth_info_json = fetch(auth_url,headers=headers)
auth_info = json.loads(auth_info_json)
data = auth_info['response']['result']['data']
if data['plugin']['key'] == 'social_login':
if data['plugin']['data']['status'] == 'success':
userdata = data['user']
self.profile = userdata['identity']
source = self.profile['source']['key']
mapping = self.mappings.get(source,self.mappings['default'])
user = mapping(self.profile)
except (ValueError, KeyError):
pass
if user is None and self.on_login_failure:
redirect(self.on_login_failure)
return user
示例5: get_user
# 需要导入模块: from gluon import tools [as 别名]
# 或者: from gluon.tools import fetch [as 别名]
def get_user(self):
request = self.request
user = None
if request.vars.token:
try:
auth_url = self.auth_base_url + self.api_secret + "/" + request.vars.token
json_data = fetch(auth_url, headers={'User-Agent': "LoginRadius - Python - SDK"})
self.profile = json.loads(json_data)
provider = self.profile['Provider']
mapping = self.mappings.get(provider, self.mappings['default'])
user = mapping(self.profile)
except (JSONDecodeError, KeyError):
pass
if user is None and self.on_login_failure:
redirect(self.on_login_failure)
return user
示例6: get_user
# 需要导入模块: from gluon import tools [as 别名]
# 或者: from gluon.tools import fetch [as 别名]
def get_user(self):
request = self.request
user = None
if request.vars.connection_token:
auth_url = "https://%s.api.oneall.com/connections/%s.json" % \
(self.domain, request.vars.connection_token)
auth_pw = "%s:%s" % (self.public_key,self.private_key)
auth_pw = base64.b64encode(auth_pw)
headers = dict(Authorization="Basic %s" % auth_pw)
try:
auth_info_json = fetch(auth_url,headers=headers)
auth_info = json.loads(auth_info_json)
data = auth_info['response']['result']['data']
if data['plugin']['key'] == 'social_login':
if data['plugin']['data']['status'] == 'success':
userdata = data['user']
self.profile = userdata['identity']
source = self.profile['source']['key']
mapping = self.mappings.get(source,self.mappings['default'])
user = mapping(self.profile)
except (JSONDecodeError, KeyError):
pass
if user is None and self.on_login_failure:
redirect(self.on_login_failure)
return user
示例7: get_user
# 需要导入模块: from gluon import tools [as 别名]
# 或者: from gluon.tools import fetch [as 别名]
def get_user(self):
request = self.request
if request.vars.assertion:
audience = self.audience
issuer = self.issuer
assertion = XML(request.vars.assertion, sanitize=True)
verify_data = {'assertion': assertion, 'audience': audience}
auth_info_json = fetch(self.verify_url, data=verify_data)
j = json.loads(auth_info_json)
epoch_time = int(time.time() * 1000) # we need 13 digit epoch time
if j["status"] == "okay" and j["audience"] == audience and j['issuer'] == issuer and j['expires'] >= epoch_time:
return dict(email=j['email'])
elif self.on_login_failure:
#print "status: ", j["status"]=="okay", j["status"]
#print "audience:", j["audience"]==audience, j["audience"], audience
#print "issuer: ", j["issuer"]==issuer, j["issuer"], issuer
#print "expires: ", j["expires"] >= epoch_time, j["expires"], epoch_time
redirect(self.on_login_failure)
else:
redirect('https://login.persona.org')
return None