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


Python oauth2.SignatureMethod_HMAC_SHA1方法代码示例

本文整理汇总了Python中oauth2.SignatureMethod_HMAC_SHA1方法的典型用法代码示例。如果您正苦于以下问题:Python oauth2.SignatureMethod_HMAC_SHA1方法的具体用法?Python oauth2.SignatureMethod_HMAC_SHA1怎么用?Python oauth2.SignatureMethod_HMAC_SHA1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth2的用法示例。


在下文中一共展示了oauth2.SignatureMethod_HMAC_SHA1方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import SignatureMethod_HMAC_SHA1 [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: signed_request

# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import SignatureMethod_HMAC_SHA1 [as 别名]
def signed_request(url, access_token=None):
    ''' return a signed request. Usually not used, save for specific
        functions like deriving a preview-clip URL.
    '''
    consumer = _consumer()

    req = oauth.Request.from_consumer_and_token(
                consumer,
                http_url=url,
                is_form_encoded=True,
                parameters={'country':api_settings.country})

    signing_method = oauth.SignatureMethod_HMAC_SHA1()
    req.sign_request(signing_method, consumer, access_token)

    return req 
开发者ID:mlachmish,项目名称:MusicGenreClassification,代码行数:18,代码来源:oauth7digital.py

示例3: use_access_token

# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import SignatureMethod_HMAC_SHA1 [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

示例4: get_request_token

# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import SignatureMethod_HMAC_SHA1 [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

示例5: get_access_token

# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import SignatureMethod_HMAC_SHA1 [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

示例6: prepare_request

# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import SignatureMethod_HMAC_SHA1 [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

示例7: __init__

# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import SignatureMethod_HMAC_SHA1 [as 别名]
def __init__(self):
        super().__init__()

        self.oauth_server = oauth2.Server()
        signature_method = oauth2.SignatureMethod_HMAC_SHA1()
        self.oauth_server.add_signature_method(signature_method)
        self.oauth_consumer = oauth2.Consumer(
            self.consumer_key, self.consumer_secret) 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:10,代码来源:request_validator.py

示例8: server

# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import SignatureMethod_HMAC_SHA1 [as 别名]
def server(self):
        result = oauth.Server()
        result.add_signature_method(oauth.SignatureMethod_PLAINTEXT())
        result.add_signature_method(oauth.SignatureMethod_HMAC_SHA1())
        return result 
开发者ID:apache,项目名称:allura,代码行数:7,代码来源:rest.py

示例9: test_oauth_workflow

# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import SignatureMethod_HMAC_SHA1 [as 别名]
def test_oauth_workflow(self):
        request_token_url = 'http://testserver' + reverse('api:oauth_request_token')
        authorize_token_url = 'http://testserver' + reverse('api:oauth_user_authorization')

        # create consumer for tests
        c = Client()
        c.login_user('ggbaker')
        c.logout()
        consumer = Consumer(name='Test Consumer', description='Consumer to do some tests with', status=ACCEPTED,
                     user=User.objects.get(username='ggbaker'), xauth_allowed=False)
        consumer.generate_random_codes()
        consumer.save()
        ci = ConsumerInfo(consumer=consumer)
        ci.admin_contact = 'the_developer@example.com'
        ci.permissions = ['courses', 'grades']
        ci.save()

        # generate request token
        oauth_request = oauth.Request.from_consumer_and_token(consumer, http_url=request_token_url,
                                                              parameters={'oauth_callback': 'oob'})
        oauth_request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, None)

        resp = c.get(request_token_url, **oauth_request.to_header())
        self.assertEqual(resp.status_code, 200)
        request_token = dict(urllib.parse.parse_qsl(resp.content.decode('utf8')))

        # get auth verifier
        c.login_user('ggbaker')
        resp = c.get(authorize_token_url, {'oauth_token': request_token['oauth_token']})
        self.assertEqual(resp.status_code, 200)
        resp = c.post(authorize_token_url, {'oauth_token': request_token['oauth_token'], 'authorize_access': 'on'})
        self.assertEqual(resp.status_code, 200)
        parser = etree.HTMLParser()
        root = etree.fromstring(resp.content, parser=parser)
        verifier_elt = root.xpath('//*[@id="verifier"]')[0]
        oauth_verifier = verifier_elt.text.strip()
        c.logout()

        # get access token
        token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
        token.set_verifier(oauth_verifier)
        oauth_request = oauth.Request.from_consumer_and_token(consumer, token, http_url=authorize_token_url)
        oauth_request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token)

        resp = c.get(authorize_token_url, **oauth_request.to_header())
        # TODO: this is failing for some reason, but succeeds in the demo scripts
        #self.assertEqual(resp.status_code, 200)
        #access_token = dict(urllib.parse.parse_qsl(response.content.decode('utf8'))) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:50,代码来源:tests.py

示例10: generate_launch_data

# 需要导入模块: import oauth2 [as 别名]
# 或者: from oauth2 import SignatureMethod_HMAC_SHA1 [as 别名]
def generate_launch_data(self):
        # Validate params
        if not self.has_required_params():
            raise InvalidLTIConfigError('ToolConsumer does not have all required attributes: consumer_key = %s, consumer_secret = %s, resource_link_id = %s, launch_url = %s' % (
                self.consumer_key, self.consumer_secret, self.resource_link_id, self.launch_url))

        params = self.to_params()
        params['lti_version'] = 'LTI-1.0'
        params['lti_message_type'] = 'basic-lti-launch-request'

        # Get new OAuth consumer
        consumer = oauth2.Consumer(key=self.consumer_key,
                                   secret=self.consumer_secret)

        params.update({
            'oauth_nonce': str(generate_identifier()),
            'oauth_timestamp': str(int(time.time())),
            'oauth_scheme': 'body',
            'oauth_consumer_key': consumer.key
        })

        uri = urlparse(self.launch_url)
        if uri.query != '':
            for param in uri.query.split('&'):
                key, val = param.split('=')
                if params.get(key) == None:
                    params[key] = str(val)

        request = oauth2.Request(method='POST',
                                 url=self.launch_url,
                                 parameters=params)

        signature_method = oauth2.SignatureMethod_HMAC_SHA1()
        request.sign_request(signature_method, consumer, None)

        # Request was made by an HTML form in the user's browser.
        # Return the dict of post parameters ready for embedding
        # in an html view.
        return_params = {}
        for key in request:
            if request[key] == None:
                return_params[key] = None
            elif isinstance(request[key], list):
                return_params[key] = request.get_parameter(key)
            else:
                return_params[key] = unquote(request.get_parameter(key))
        return return_params 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:49,代码来源:tool_consumer.py


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