本文整理汇总了Python中oauth2.Client方法的典型用法代码示例。如果您正苦于以下问题:Python oauth2.Client方法的具体用法?Python oauth2.Client怎么用?Python oauth2.Client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2
的用法示例。
在下文中一共展示了oauth2.Client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def login(self, username, password):
'''Authenticate using XAuth variant of OAuth.
:param str username: Username or email address for the relevant account
:param str password: Password for the account
'''
response = self.request(
ACCESS_TOKEN,
{
'x_auth_mode': 'client_auth',
'x_auth_username': username,
'x_auth_password': password
},
returns_json=False
)
token = dict(parse_qsl(response['data'].decode()))
self.token = oauth.Token(
token['oauth_token'], token['oauth_token_secret'])
self.oauth_client = oauth.Client(self.consumer, self.token)
示例2: __init__
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def __init__(self, key, secret, email, password, cartodb_domain, host='carto.com', protocol='https', proxy_info=None, *args, **kwargs):
super(CartoDBOAuth, self).__init__(cartodb_domain, host, protocol, *args, **kwargs)
self.consumer_key = key
self.consumer_secret = secret
consumer = oauth.Consumer(self.consumer_key, self.consumer_secret)
client = oauth.Client(consumer, proxy_info=proxy_info)
client.set_signature_method = oauth.SignatureMethod_HMAC_SHA1()
params = {}
params["x_auth_username"] = email
params["x_auth_password"] = password
params["x_auth_mode"] = 'client_auth'
# Get Access Token
access_token_url = ACCESS_TOKEN_URL % {'user': cartodb_domain, 'domain': host, 'protocol': protocol}
resp, token = client.request(access_token_url, method="POST", body=urllib.urlencode(params))
access_token = dict(urlparse.parse_qsl(token))
token = oauth.Token(access_token['oauth_token'], access_token['oauth_token_secret'])
# prepare client
self.client = oauth.Client(consumer, token)
示例3: get_oauth_token
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def get_oauth_token(config):
global consumer
global client
global req_token
consumer = oauth.Consumer(config.consumer_key, config.consumer_secret)
client = oauth.Client(consumer)
resp, content = client.request(config.request_token_url, 'GET')
if resp['status'] != '200':
raise Exception("Invalid response {}".format(resp['status']))
request_token = dict(parse_qsl(content.decode('utf-8')))
req_token = RequestToken(**request_token)
示例4: callback
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def callback():
global req_token
global consumer
config = read_config()
oauth_verifier = request.args.get('oauth_verifier', '')
token = oauth.Token(req_token.oauth_token,
req_token.oauth_token_secret)
token.set_verifier(oauth_verifier)
client = oauth.Client(consumer, token)
resp, content = client.request(config.access_token_url, 'POST')
access_token = dict(parse_qsl(content.decode('utf-8')))
with open('.twitterauth', 'w') as req_auth:
file_content = yaml.dump(access_token, default_flow_style=False)
req_auth.write(file_content)
return 'All set! You can close the browser window and stop the server.'
示例5: post_outcome_request
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def post_outcome_request(self):
"""
POST an OAuth signed request to the Tool Consumer.
"""
if not self.has_required_attributes():
raise InvalidLTIConfigError(
'OutcomeRequest does not have all required attributes')
consumer = oauth2.Consumer(key=self.consumer_key,
secret=self.consumer_secret)
client = oauth2.Client(consumer)
response, content = client.request(
self.lis_outcome_service_url,
'POST',
body=self.generate_request_xml(),
headers={'Content-Type': 'application/xml'})
self.outcome_response = OutcomeResponse.from_post_response(response,
content)
return self.outcome_response
示例6: make_request
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def make_request(self, url, method="GET", body="", headers=None):
"""Makes a request to the TradeKing API."""
consumer = Consumer(key=TRADEKING_CONSUMER_KEY,
secret=TRADEKING_CONSUMER_SECRET)
token = Token(key=TRADEKING_ACCESS_TOKEN,
secret=TRADEKING_ACCESS_TOKEN_SECRET)
client = Client(consumer, token)
body_bytes = body.encode("utf-8")
self.logs.debug("TradeKing request: %s %s %s %s" %
(url, method, body_bytes, headers))
response, content = client.request(url, method=method,
body=body_bytes,
headers=headers)
self.logs.debug("TradeKing response: %s %s" % (response, content))
try:
return loads(content)
except ValueError:
self.logs.error("Failed to decode JSON response: %s" % content)
return None
示例7: __init__
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def __init__(self, oauth_key, oauth_secret):
self.consumer = oauth.Consumer(oauth_key, oauth_secret)
self.oauth_client = oauth.Client(self.consumer)
self.token = None
示例8: fetch
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def fetch(self, url, post=False, **kw):
client = oauth.Client(self.consumer, self.token, None, self.timeout)
headers, data = client.request(url,
method='POST' if post else 'GET',
body=urllib.urlencode(kw))
if headers['content-type'].startswith(('application/json', 'text/javascript')):
data = json.loads(data)
return data
示例9: step1_get_authorize_url
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def step1_get_authorize_url(self, oauth_callback='oob'):
"""Returns a URI to redirect to the provider.
oauth_callback - Either the string 'oob' for a non-web-based application,
or a URI that handles the callback from the authorization
server.
If oauth_callback is 'oob' then pass in the
generated verification code to step2_exchange,
otherwise pass in the query parameters received
at the callback uri to step2_exchange.
"""
consumer = oauth.Consumer(self.consumer_key, self.consumer_secret)
client = oauth.Client(consumer)
headers = {
'user-agent': self.user_agent,
'content-type': 'application/x-www-form-urlencoded'
}
body = urllib.urlencode({'oauth_callback': oauth_callback})
uri = _oauth_uri('request', self.discovery, self.params)
resp, content = client.request(uri, 'POST', headers=headers,
body=body)
if resp['status'] != '200':
logging.error('Failed to retrieve temporary authorization: %s', content)
raise RequestError('Invalid response %s.' % resp['status'])
self.request_token = dict(parse_qsl(content))
auth_params = copy.copy(self.params)
auth_params['oauth_token'] = self.request_token['oauth_token']
return _oauth_uri('authorize', self.discovery, auth_params)
示例10: step2_exchange
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def step2_exchange(self, verifier):
"""Exhanges an authorized request token
for OAuthCredentials.
Args:
verifier: string, dict - either the verifier token, or a dictionary
of the query parameters to the callback, which contains
the oauth_verifier.
Returns:
The Credentials object.
"""
if not (isinstance(verifier, str) or isinstance(verifier, unicode)):
verifier = verifier['oauth_verifier']
token = oauth.Token(
self.request_token['oauth_token'],
self.request_token['oauth_token_secret'])
token.set_verifier(verifier)
consumer = oauth.Consumer(self.consumer_key, self.consumer_secret)
client = oauth.Client(consumer, token)
headers = {
'user-agent': self.user_agent,
'content-type': 'application/x-www-form-urlencoded'
}
uri = _oauth_uri('access', self.discovery, self.params)
resp, content = client.request(uri, 'POST', headers=headers)
if resp['status'] != '200':
logging.error('Failed to retrieve access token: %s', content)
raise RequestError('Invalid response %s.' % resp['status'])
oauth_params = dict(parse_qsl(content))
token = oauth.Token(
oauth_params['oauth_token'],
oauth_params['oauth_token_secret'])
return OAuthCredentials(consumer, token, self.user_agent)
示例11: __init__
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def __init__(self, consumer_key, consumer_secret, token_key, token_secret):
consumer = Consumer(key=consumer_key, secret=consumer_secret)
token = Token(key=token_key, secret=token_secret)
proxy_info = None
if hasattr(settings, 'PROXY_HOST') and \
hasattr(settings, 'PROXY_PORT'):
proxy_info = ProxyInfo(
proxy_type=PROXY_TYPE_HTTP,
proxy_host=settings.PROXY_HOST,
proxy_port=settings.PROXY_PORT)
self.client = Client(
consumer=consumer,
token=token,
proxy_info=proxy_info)
示例12: lrs_oauth_callback
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def lrs_oauth_callback(request):
import os
import urlparse
user_id = request.user.id
user = User.objects.get(id=user_id)
status = request.GET.get('status')
if status is not None and status == 'fail':
return HttpResponseServerError('Could not get access token.')
request_token = OAuthTempRequestToken.objects.get(user_id=user)
verifier = request.GET.get('oauth_verifier')
token = oauth.Token(request_token.token, request_token.secret)
request_token.delete() #delete temp token
token.set_verifier(verifier)
# Get Consumer info #Todo: change (most definitely) (IMPORTANT!!)
# consumer_key, consumer_secret = get_consumer_key_and_secret()
app = ClientApp.objects.get(id = request_token.clientapp.id)
client = oauth.Client(oauth.Consumer(app.get_key(), app.get_secret()), token)
# Exchange request_token for authed and verified access_token
resp,content = client.request(app.get_access_token_url(), "POST")
access_token = dict(urlparse.parse_qsl(content))
if access_token['oauth_token']:
UserAccessToken_LRS(user=user, access_token=access_token['oauth_token'],
access_token_secret=access_token['oauth_token_secret'],
clientapp = app).save()
from django.shortcuts import render_to_response
return render_to_response('xapi/get_access_token_successful.html')
示例13: request_2legged
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def request_2legged(url, http_method="GET"):
client = oauth.Client(_consumer())
response, content = client.request(
url,
headers = {"Content-Type":"application/x-www-form-urlencoded"},
body="country=%s" % api_settings.country,
method = http_method
)
return response, content
示例14: request_access_token
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def request_access_token(token):
client = oauth.Client(_consumer(), token=token)
response, content = client.request(
ACCESS_TOKEN_URL,
headers={"Content-Type":"application/x-www-form-urlencoded"}
)
return _token_from_response_content(content)
示例15: request_3legged
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Client [as 别名]
def request_3legged(url, access_token, http_method="GET", body=''):
''' Once you have an access_token authorized by a customer,
execute a request on their behalf
'''
client = oauth.Client(_consumer(), token=access_token)
response = client.request(
url,
headers={"Content-Type":"application/x-www-form-urlencoded"},
method=http_method,
body=body
)
return response