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


Python oauth1.Client类代码示例

本文整理汇总了Python中oauthlib.oauth1.Client的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: OAuth1

class OAuth1(object):
    """Signs the request using OAuth 1 (RFC5849)"""

    def __init__(
        self,
        client_key,
        client_secret=None,
        resource_owner_key=None,
        resource_owner_secret=None,
        callback_uri=None,
        signature_method=SIGNATURE_HMAC,
        signature_type=SIGNATURE_TYPE_AUTH_HEADER,
        rsa_key=None,
        verifier=None,
        decoding="utf-8",
    ):

        try:
            signature_type = signature_type.upper()
        except AttributeError:
            pass

        self.client = Client(
            client_key,
            client_secret,
            resource_owner_key,
            resource_owner_secret,
            callback_uri,
            signature_method,
            signature_type,
            rsa_key,
            verifier,
            decoding=decoding,
        )

    def __call__(self, r):
        """Add OAuth parameters to the request.

        Parameters may be included from the body if the content-type is
        urlencoded, if no content type is set a guess is made.
        """
        # Overwriting url is safe here as request will not modify it past
        # this point.

        content_type = r.headers.get("Content-Type".encode("utf-8"), "")
        if not isinstance(content_type, unicode):
            content_type = content_type.decode("utf-8")

        is_form_encoded = CONTENT_TYPE_FORM_URLENCODED in content_type

        if is_form_encoded or extract_params(r.body):
            r.headers["Content-Type"] = CONTENT_TYPE_FORM_URLENCODED
            r.url, r.headers, r.body = self.client.sign(unicode(r.url), unicode(r.method), r.body or "", r.headers)
        else:
            # Omit body data in the signing of non form-encoded requests
            r.url, r.headers, _ = self.client.sign(unicode(r.url), unicode(r.method), None, r.headers)

        r.url = to_native_str(r.url)

        return r
开发者ID:rude64,项目名称:splunk-app-twitter,代码行数:60,代码来源:core.py

示例2: _log_correct_authorization_header

    def _log_correct_authorization_header(self, request):
        """
        Helper function that logs proper HTTP Authorization header for a given request

        Used only in debug situations, this logs the correct Authorization header based on
        the request header and body according to OAuth 1 Body signing

        Arguments:
            request (xblock.django.request.DjangoWebobRequest):  Request object to log Authorization header for

        Returns:
            nothing
        """
        sha1 = hashlib.sha1()
        sha1.update(request.body)
        oauth_body_hash = unicode(base64.b64encode(sha1.digest()))
        log.debug("[LTI] oauth_body_hash = {}".format(oauth_body_hash))
        client_key, client_secret = self.get_client_key_secret()
        client = Client(client_key, client_secret)
        mock_request = mock.Mock(
            uri=unicode(urllib.unquote(request.url)),
            headers=request.headers,
            body=u"",
            decoded_body=u"",
            http_method=unicode(request.method),
        )
        params = client.get_oauth_params(mock_request)
        mock_request.oauth_params = params
        mock_request.oauth_params.append((u'oauth_body_hash', oauth_body_hash))
        sig = client.get_oauth_signature(mock_request)
        mock_request.oauth_params.append((u'oauth_signature', sig))

        _, headers, _ = client._render(mock_request)  # pylint: disable=protected-access
        log.debug("\n\n#### COPY AND PASTE AUTHORIZATION HEADER ####\n{}\n####################################\n\n"
                  .format(headers['Authorization']))
开发者ID:dehamzah,项目名称:edx-platform,代码行数:35,代码来源:lti_2_util.py

示例3: get_access_token

def get_access_token(consumer_key,
                     consumer_secret,
                     req_token_key,
                     req_token_secret,
                     verifier,
                     access_token_url,
                     validate_certs=True):
    method = 'GET'
    params = {'format': 'json', 'oauth_callback': 'oob'}
    # they're really serious about that oob
    full_url = access_token_url + "&" + urllib.urlencode(params)
    client = OAClient(consumer_key,
                      client_secret=consumer_secret,
                      resource_owner_key=req_token_key,
                      resource_owner_secret=req_token_secret,
                      verifier=verifier,
                      signature_type=SIGNATURE_TYPE_QUERY)
    full_url, headers, body = client.sign(full_url, method)

    client = httplib2.Http()
    client.disable_ssl_certificate_validation = not validate_certs
    resp, content = client.request(full_url, method=method)
    try:
        resp_dict = json.loads(content)
        acc_token_key, acc_token_secret = resp_dict['key'], resp_dict['secret']
    except:
        raise ValueError('access token step failed: %s\n\nheaders, etc.: %s'
                         % (content, pformat(resp)))
    return acc_token_key, acc_token_secret
开发者ID:hatnote,项目名称:omwcat,代码行数:29,代码来源:mwoauth.py


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