本文整理汇总了Python中oauth2.Consumer方法的典型用法代码示例。如果您正苦于以下问题:Python oauth2.Consumer方法的具体用法?Python oauth2.Consumer怎么用?Python oauth2.Consumer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2
的用法示例。
在下文中一共展示了oauth2.Consumer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [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)
示例2: oauth_login
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [as 别名]
def oauth_login(self, url, oauth_token, oauth_token_secret,
consumer_key='anonymous', consumer_secret='anonymous'):
"""Authenticate using the OAUTH method.
This only works with IMAP servers that support OAUTH (e.g. Gmail).
"""
if oauth_module:
token = oauth_module.Token(oauth_token, oauth_token_secret)
consumer = oauth_module.Consumer(consumer_key, consumer_secret)
xoauth_callable = lambda x: oauth_module.build_xoauth_string(url,
consumer,
token)
return self._command_and_check('authenticate', 'XOAUTH',
xoauth_callable, unpack=True)
else:
raise self.Error(
'The optional oauth2 package is needed for OAUTH authentication')
示例3: get_oauth_token
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [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: lookup_consumer
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [as 别名]
def lookup_consumer(self, key):
"""
Search through keys
"""
if not self.consumers:
log.critical(("No consumers defined in settings."
"Have you created a configuration file?"))
return None
consumer = self.consumers.get(key)
if not consumer:
log.info("Did not find consumer, using key: %s ", key)
return None
secret = consumer.get('secret', None)
if not secret:
log.critical(('Consumer %s, is missing secret'
'in settings file, and needs correction.'), key)
return None
return oauth2.Consumer(key, secret)
示例5: post_outcome_request
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [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 Consumer [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 Consumer [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: use_access_token
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [as 别名]
def use_access_token(oauth_token, oauth_secret):
consumer = oauth.Consumer(key='9fdce0e111a1489eb5a42eab7a84306b', secret='liqutXmqJpKmetfs')
token = oauth.Token(oauth_token, oauth_secret)
oauth_request = oauth.Request.from_consumer_and_token(consumer, http_url=RESOURCE_URL)
oauth_request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token)
# get the resource
response = requests.get(RESOURCE_URL, headers=oauth_request.to_header())
return response.text
示例9: get_request_token
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [as 别名]
def get_request_token(with_callback=True):
consumer = oauth.Consumer(key='9fdce0e111a1489eb5a42eab7a84306b', secret='liqutXmqJpKmetfs')
if with_callback:
callback = CALLBACK_URL
else:
callback = 'oob'
oauth_request = oauth.Request.from_consumer_and_token(consumer, http_url=REQUEST_TOKEN_URL, parameters={'oauth_callback': callback})
oauth_request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, None)
response = requests.get(REQUEST_TOKEN_URL, headers=oauth_request.to_header())
request_token = dict(urllib.parse.parse_qsl(response.content.decode('utf8')))
return request_token
示例10: get_access_token
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [as 别名]
def get_access_token(oauth_token, oauth_secret, oauth_verifier):
consumer = oauth.Consumer(key='9fdce0e111a1489eb5a42eab7a84306b', secret='liqutXmqJpKmetfs')
token = oauth.Token(oauth_token, oauth_secret)
token.set_verifier(oauth_verifier)
oauth_request = oauth.Request.from_consumer_and_token(consumer, token, http_url=ACCESS_TOKEN_URL)
oauth_request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token)
response = requests.get(ACCESS_TOKEN_URL, headers=oauth_request.to_header())
access_token = dict(urllib.parse.parse_qsl(response.content.decode('utf8')))
return access_token
示例11: authenticate
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [as 别名]
def authenticate(self, url, consumer, token):
if consumer is not None and not isinstance(consumer, oauth2.Consumer):
raise ValueError("Invalid consumer.")
if token is not None and not isinstance(token, oauth2.Token):
raise ValueError("Invalid token.")
self.docmd('AUTH', 'XOAUTH %s' % \
base64.b64encode(oauth2.build_xoauth_string(url, consumer, token)))
示例12: authenticate
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [as 别名]
def authenticate(self, url, consumer, token):
if consumer is not None and not isinstance(consumer, oauth2.Consumer):
raise ValueError("Invalid consumer.")
if token is not None and not isinstance(token, oauth2.Token):
raise ValueError("Invalid token.")
imaplib.IMAP4_SSL.authenticate(self, 'XOAUTH',
lambda x: oauth2.build_xoauth_string(url, consumer, token))
示例13: __init__
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [as 别名]
def __init__(self, key, secret, scopes=(), timeout=None):
self.consumer = oauth.Consumer(key, secret)
self.timeout = timeout
self.scopes = scopes
self.token = None
示例14: prepare_request
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [as 别名]
def prepare_request(url, url_params):
reqconfig = read_reqauth()
config = read_config()
token = oauth.Token(
key=reqconfig.oauth_token,
secret=reqconfig.oauth_token_secret)
consumer = oauth.Consumer(
key=config.consumer_key,
secret=config.consumer_secret)
params = {
'oauth_version': "1.0",
'oauth_nonce': oauth.generate_nonce(),
'oauth_timestamp': str(int(time.time()))
}
params['oauth_token'] = token.key
params['oauth_consumer_key'] = consumer.key
params.update(url_params)
req = oauth.Request(method="GET", url=url, parameters=params)
signature_method = oauth.SignatureMethod_HMAC_SHA1()
req.sign_request(signature_method, consumer, token)
return req.to_url()
示例15: __init__
# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import Consumer [as 别名]
def __init__(self, consumer, token, user_agent):
"""
consumer - An instance of oauth.Consumer.
token - An instance of oauth.Token constructed with
the access token and secret.
user_agent - The HTTP User-Agent to provide for this application.
"""
self.consumer = consumer
self.token = token
self.user_agent = user_agent
self.store = None
# True if the credentials have been revoked
self._invalid = False