当前位置: 首页>>代码示例>>Python>>正文


Python oauth2.Consumer方法代码示例

本文整理汇总了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) 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:25,代码来源:cartodb.py

示例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') 
开发者ID:Schibum,项目名称:sndlatr,代码行数:19,代码来源:imapclient.py

示例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) 
开发者ID:PacktPublishing,项目名称:Python-Programming-Blueprints,代码行数:19,代码来源:twitter_auth.py

示例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) 
开发者ID:mitodl,项目名称:pylti,代码行数:22,代码来源:common.py

示例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 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:24,代码来源:outcome_request.py

示例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 
开发者ID:maxbbraun,项目名称:trump2cash,代码行数:24,代码来源:trading.py

示例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 
开发者ID:mdorn,项目名称:pyinstapaper,代码行数:6,代码来源:instapaper.py

示例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 
开发者ID:sfu-fas,项目名称:coursys,代码行数:11,代码来源:demo4_use_access_token.py

示例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 
开发者ID:sfu-fas,项目名称:coursys,代码行数:14,代码来源:demo2_get_request_token.py

示例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 
开发者ID:sfu-fas,项目名称:coursys,代码行数:12,代码来源:demo3_get_access_token.py

示例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))) 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:11,代码来源:smtp.py

示例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)) 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:11,代码来源:imap.py

示例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 
开发者ID:Net-ng,项目名称:kansha,代码行数:7,代码来源:oauth_providers.py

示例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() 
开发者ID:PacktPublishing,项目名称:Python-Programming-Blueprints,代码行数:31,代码来源:request.py

示例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 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:16,代码来源:oauth.py


注:本文中的oauth2.Consumer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。