本文整理汇总了Python中social_auth.utils.dsa_urlopen函数的典型用法代码示例。如果您正苦于以下问题:Python dsa_urlopen函数的具体用法?Python dsa_urlopen怎么用?Python dsa_urlopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dsa_urlopen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_data
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
url = GITHUB_USER_DATA_URL + "?" + urlencode({"access_token": access_token})
try:
data = simplejson.load(dsa_urlopen(url))
except ValueError:
data = None
# if we have a github organization defined, test that the current users
# is a member of that organization.
if data and self.GITHUB_ORGANIZATION:
member_url = GITHUB_ORGANIZATION_MEMBER_OF_URL.format(
org=self.GITHUB_ORGANIZATION, username=data.get("login")
)
try:
response = dsa_urlopen(member_url)
except HTTPError:
data = None
else:
# if the user is a member of the organization, response code
# will be 204, see:
# http://developer.github.com/v3/orgs/members/#response-if-requester-is-an-organization-member-and-user-is-a-member
if not response.code == 204:
data = None
return data
示例2: user_data
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
url = GITHUB_USER_DATA_URL + '?' + urlencode({
'access_token': access_token
})
try:
data = simplejson.load(dsa_urlopen(url))
except ValueError:
data = None
# if we have a github organization defined, test that the current users
# is a member of that organization.
if data and self.GITHUB_ORGANIZATION:
member_url = GITHUB_ORGANIZATION_MEMBER_OF_URL.format(
org=self.GITHUB_ORGANIZATION,
username=data.get('login')
) + '?' + urlencode({
'access_token': access_token
})
try:
response = dsa_urlopen(member_url)
except HTTPError:
data = None
else:
# if the user is a member of the organization, response code
# will be 204, see http://bit.ly/ZS6vFl
if response.code != 204:
raise AuthFailed('User doesn\'t belong to the '
'organization')
return data
示例3: vk_api
def vk_api(method, data, is_app=False):
"""Calls VK OpenAPI method
https://vk.com/apiclub,
https://vk.com/pages.php?o=-1&p=%C2%FB%EF%EE%EB%ED%E5%ED%E8%E5%20%E7'
%E0%EF%F0%EE%F1%EE%E2%20%EA%20API
"""
# We need to perform server-side call if no access_token
if not 'access_token' in data:
if not 'v' in data:
data['v'] = VK_API_VERSION
if not 'api_id' in data:
data['api_id'] = setting('VKAPP_APP_ID' if is_app else 'VK_APP_ID')
data['method'] = method
data['format'] = 'json'
url = VK_SERVER_API_URL
secret = setting('VKAPP_API_SECRET' if is_app else 'VK_API_SECRET')
param_list = sorted(list(item + '=' + data[item] for item in data))
data['sig'] = md5(''.join(param_list) + secret).hexdigest()
else:
url = VK_API_URL + method
params = urlencode(data)
url += '?' + params
try:
return json.load(dsa_urlopen(url))
except (TypeError, KeyError, IOError, ValueError, IndexError):
log('error', 'Could not load data from vk.com',
exc_info=True, extra=dict(data=data))
return None
示例4: auth_complete
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
access_token = None
expires = None
if 'code' in self.data:
state = self.validate_state()
url = ACCESS_TOKEN + urlencode({
'client_id': backend_setting(self, self.SETTINGS_KEY_NAME),
'redirect_uri': self.get_redirect_uri(state),
'client_secret': backend_setting(
self,
self.SETTINGS_SECRET_NAME
),
'code': self.data['code']
})
try:
payload = dsa_urlopen(url)
except HTTPError:
raise AuthFailed(self, 'There was an error authenticating '
'the app')
response = payload.read()
#parsed_response = cgi.parse_qs(response)
parsed_response = json.loads(response)
# print('***********************************************')
# print(url)
# print(response)
# print(parsed_response)
# print(parsed_response['access_token'])
# print(parsed_response['expires_in'])
# print('***********************************************')
access_token = parsed_response['access_token']
if 'expires' in parsed_response:
expires = parsed_response['expires']
if 'signed_request' in self.data:
response = load_signed_request(
self.data.get('signed_request'),
backend_setting(self, self.SETTINGS_SECRET_NAME)
)
if response is not None:
access_token = response.get('access_token') or\
response.get('oauth_token') or\
self.data.get('access_token')
if 'expires' in response:
expires = response['expires']
if access_token:
return self.do_auth(access_token, expires=expires, *args, **kwargs)
else:
if self.data.get('error') == 'access_denied':
raise AuthCanceled(self)
else:
raise AuthException(self)
示例5: response
def response(self):
if not hasattr(self, '_response'):
access_token = None
expires = None
if 'code' in self.data:
state = self.validate_state()
url = ACCESS_TOKEN + urlencode({
'client_id': backend_setting(self, self.SETTINGS_KEY_NAME),
'redirect_uri': self.get_redirect_uri(state),
'client_secret': backend_setting(self,
self.SETTINGS_SECRET_NAME),
'code': self.data['code']
})
try:
self._response = cgi.parse_qs(dsa_urlopen(url).read())
except HTTPError:
raise AuthFailed(self, 'There was an error authenticating '
'the app')
if 'signed_request' in self.data:
self._response = load_signed_request(self.data.get('signed_request'),
backend_setting(
self,
self.SETTINGS_SECRET_NAME))
return self._response
示例6: user_data
def user_data(self, access_token, *args, **kwargs):
"""
Grab user profile information from facebook.
returns: dict or None
"""
data = None
params = backend_setting(self, self.EXTRA_PARAMS_VAR_NAME, {})
params['access_token'] = access_token
url = FACEBOOK_ME + urlencode(params)
try:
response = dsa_urlopen(url)
data = json.load(response)
except ValueError:
extra = {'access_token': sanitize_log_data(access_token)}
log('error', 'Could not load user data from Facebook.',
exc_info=True, extra=extra)
except HTTPError:
extra = {'access_token': sanitize_log_data(access_token)}
log('error', 'Error validating access token.',
exc_info=True, extra=extra)
raise AuthTokenError(self)
else:
log('debug', 'Found user data for token %s',
sanitize_log_data(access_token), extra={'data': data})
return data
示例7: odnoklassniki_api
def odnoklassniki_api(data, api_url, public_key, client_secret,
request_type='oauth'):
''' Calls Odnoklassniki REST API method
http://dev.odnoklassniki.ru/wiki/display/ok/Odnoklassniki+Rest+API
'''
data.update({
'application_key': public_key,
'format': 'JSON'
})
if request_type == 'oauth':
data['sig'] = odnoklassniki_oauth_sig(data, client_secret)
elif request_type == 'iframe_session':
data['sig'] = odnoklassniki_iframe_sig(data,
data['session_secret_key'])
elif request_type == 'iframe_nosession':
data['sig'] = odnoklassniki_iframe_sig(data, client_secret)
else:
msg = 'Unknown request type {0}. How should it be signed?'
raise AuthFailed(msg.format(request_type))
params = urlencode(data)
request = Request('{0}fb.do?{1}'.format(api_url, params))
try:
return simplejson.loads(dsa_urlopen(request).read())
except (TypeError, KeyError, IOError, ValueError, IndexError):
log('error', 'Could not load data from Odnoklassniki.',
exc_info=True, extra=dict(data=params))
return None
示例8: user_data
def user_data(self, access_token):
"""Return user data provided"""
# Bitbucket has a bit of an indirect route to obtain user data from an
# authenticated query: First obtain the user's email via an
# authenticated GET
url = BITBUCKET_EMAIL_DATA_URL
request = self.oauth_request(access_token, url)
response = self.fetch_response(request)
try:
# Then retrieve the user's primary email address or the top email
email_addresses = simplejson.loads(response)
for email_address in reversed(email_addresses):
if email_address['active']:
email = email_address['email']
if email_address['primary']:
break
# Then return the user data using a normal GET with the
# BITBUCKET_USER_DATA_URL and the user's email
response = dsa_urlopen(BITBUCKET_USER_DATA_URL + email)
user_details = simplejson.load(response)['user']
user_details['email'] = email
return user_details
except ValueError:
return None
return None
示例9: auth_complete
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if self.data.get('error'):
error = self.data.get('error_description') or self.data['error']
raise AuthFailed(self, error)
state = self.validate_state()
client_id, client_secret = self.get_key_and_secret()
params = {
'grant_type': 'authorization_code', # request auth code
'code': self.data.get('code', ''), # server response code
'client_id': client_id,
'client_secret': client_secret,
'redirect_uri': self.get_redirect_uri(state)
}
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'}
request = Request(self.ACCESS_TOKEN_URL, data=urlencode(params),
headers=headers)
try:
response = simplejson.loads(dsa_urlopen(request).read())
except HTTPError, e:
if e.code == 400:
raise AuthCanceled(self)
else:
raise
示例10: refresh_token
def refresh_token(cls, token):
request = Request(
cls.REFRESH_TOKEN_URL or cls.ACCESS_TOKEN_URL,
data=urlencode(cls.refresh_token_params(token)),
headers=cls.auth_headers()
)
return cls.process_refresh_token_response(dsa_urlopen(request).read())
示例11: user_data
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
url = LIVE_USER_DATA_URL + "?" + urlencode({"access_token": access_token})
try:
return simplejson.load(dsa_urlopen(url))
except (ValueError, IOError):
raise AuthUnknownError("Error during profile retrieval, " "please, try again later")
示例12: vkontakte_api
def vkontakte_api(method, data):
"""Calls VKontakte OpenAPI method
http://vkontakte.ru/apiclub,
http://vkontakte.ru/pages.php?o=-1&p=%C2%FB%EF%EE%EB%ED%E5%ED%E8%E5%20
%E7%E0%EF%F0%EE%F1%EE%E2%20%EA%20
API
"""
# We need to perform server-side call if no access_token
if not "access_token" in data:
if not "v" in data:
data["v"] = VKONTAKTE_API_VERSION
if not "api_id" in data:
data["api_id"] = _api_get_val_fun("id", "VKONTAKTE_APP_ID")
data["method"] = method
data["format"] = "json"
url = VKONTAKTE_SERVER_API_URL
secret = _api_get_val_fun("key", "VKONTAKTE_APP_SECRET")
param_list = sorted(list(item + "=" + data[item] for item in data))
data["sig"] = md5("".join(param_list) + secret).hexdigest()
else:
url = VKONTAKTE_API_URL + method
params = urlencode(data)
url += "?" + params
try:
return simplejson.load(dsa_urlopen(url))
except (TypeError, KeyError, IOError, ValueError, IndexError):
log("error", "Could not load data from VKontakte.", exc_info=True, extra=dict(data=data))
return None
示例13: response
def response(self):
if not hasattr(self, '_response'):
if self.data.get('error'):
error = self.data.get('error_description') or self.data['error']
raise AuthFailed(self, error)
state = self.validate_state()
client_id, client_secret = self.get_key_and_secret()
params = {
'grant_type': 'authorization_code', # request auth code
'code': self.data.get('code', ''), # server response code
'client_id': client_id,
'client_secret': client_secret,
'redirect_uri': self.get_redirect_uri(state)
}
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'}
request = Request(self.ACCESS_TOKEN_URL, data=urlencode(params),
headers=headers)
try:
self._response = simplejson.loads(dsa_urlopen(request).read())
except HTTPError, e:
if e.code == 400:
raise AuthCanceled(self)
else:
raise
except (ValueError, KeyError):
raise AuthUnknownError(self)
示例14: vkontakte_api
def vkontakte_api(method, data):
"""Calls VKontakte OpenAPI method
http://vkontakte.ru/apiclub,
http://vkontakte.ru/pages.php?o=-1&p=%C2%FB%EF%EE%EB%ED%E5%ED%E8%E5%20
%E7%E0%EF%F0%EE%F1%EE%E2%20%EA%20
API
"""
# We need to perform server-side call if no access_token
if not 'access_token' in data:
if not 'v' in data:
data['v'] = VKONTAKTE_API_VERSION
if not 'api_id' in data:
data['api_id'] = _api_get_val_fun('id', 'VKONTAKTE_APP_ID')
data['method'] = method
data['format'] = 'json'
url = VKONTAKTE_SERVER_API_URL
secret = _api_get_val_fun('key', 'VKONTAKTE_APP_SECRET')
param_list = sorted(list(item + '=' + data[item] for item in data))
data['sig'] = md5(''.join(param_list) + secret).hexdigest()
else:
url = VKONTAKTE_API_URL + method
params = urlencode(data)
url += '?' + params
try:
return simplejson.load(dsa_urlopen(url))
except (TypeError, KeyError, IOError, ValueError, IndexError):
log('error', 'Could not load data from VKontakte.',
exc_info=True, extra=dict(data=data))
return None
示例15: user_data
def user_data(self, access_token, *args, **kwargs):
"""Return user data provided"""
try:
data = dsa_urlopen(DAILYMOTION_SERVER + access_token).read()
return simplejson.loads(data)
except (ValueError, HTTPError):
return None