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


Python common.Request方法代码示例

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


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

示例1: create_authorization_response

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import Request [as 别名]
def create_authorization_response(self, uri, http_method='GET', body=None,
                                      headers=None, scopes=None, credentials=None):
        """Extract response_type and route to the designated handler."""
        request = Request(
            uri, http_method=http_method, body=body, headers=headers)
        request.scopes = scopes
        # TODO: decide whether this should be a required argument
        request.user = None     # TODO: explain this in docs
        for k, v in (credentials or {}).items():
            setattr(request, k, v)
        response_type_handler = self.response_types.get(
            request.response_type, self.default_response_type_handler)
        log.debug('Dispatching response_type %s request to %r.',
                  request.response_type, response_type_handler)
        return response_type_handler.create_authorization_response(
            request, self.default_token_type) 
开发者ID:kylebebak,项目名称:Requester,代码行数:18,代码来源:authorization.py

示例2: __init__

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import Request [as 别名]
def __init__(self, request_validator, token_generator=None,
                 token_expires_in=None, refresh_token_generator=None, **kwargs):
        """Construct a client credentials grant server.
        :param request_validator: An implementation of
                                  oauthlib.oauth2.RequestValidator.
        :param token_expires_in: An int or a function to generate a token
                                 expiration offset (in seconds) given a
                                 oauthlib.common.Request object.
        :param token_generator: A function to generate a token from a request.
        :param refresh_token_generator: A function to generate a token from a
                                        request for the refresh token.
        :param kwargs: Extra parameters to pass to authorization-,
                       token-, resource-, and revocation-endpoint constructors.
        """
        self._params = {}
        refresh_grant = SocialTokenGrant(request_validator)
        bearer = BearerToken(request_validator, token_generator,
                             token_expires_in, refresh_token_generator)
        TokenEndpoint.__init__(self, default_grant_type='convert_token',
                               grant_types={
                                   'convert_token': refresh_grant,
                               },
                               default_token_type=bearer) 
开发者ID:RealmTeam,项目名称:django-rest-framework-social-oauth2,代码行数:25,代码来源:oauth2_endpoints.py

示例3: create_token_response

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import Request [as 别名]
def create_token_response(self, uri, http_method='GET', body=None,
                              headers=None, credentials=None):
        """Extract grant_type and route to the designated handler."""
        request = Request(
            uri, http_method=http_method, body=body, headers=headers)
        request.scopes = None
        request.extra_credentials = credentials

        # Make sure we consume the django request object
        request.django_request = self.pop_request_object()

        grant_type_handler = self.grant_types.get(request.grant_type,
                                                  self.default_grant_type_handler)
        log.debug('Dispatching grant_type %s request to %r.',
                  request.grant_type, grant_type_handler)
        return grant_type_handler.create_token_response(
            request, self.default_token_type) 
开发者ID:RealmTeam,项目名称:django-rest-framework-social-oauth2,代码行数:19,代码来源:oauth2_endpoints.py

示例4: test_get_oauth_params

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import Request [as 别名]
def test_get_oauth_params():
    """Verifies oauth_token is added to the list of params when an empty string."""

    client = MKMClient(
        client_key="app_token",
        client_secret="app_secret",
        resource_owner_key="",
        resource_owner_secret="",
        realm="https://sandbox.cardmarket.com",
        nonce="0987654321",
        timestamp="1234567890",
    )

    params = client.get_oauth_params(Request(uri="https://sandbox.cardmarket.com"))

    assert params[0][0] == "oauth_nonce"
    assert params[0][1] == "0987654321"
    assert params[1][0] == "oauth_timestamp"
    assert params[1][1] == "1234567890"
    assert params[2][0] == "oauth_version"
    assert params[2][1] == "1.0"
    assert params[3][0] == "oauth_signature_method"
    assert params[3][1] == "HMAC-SHA1"
    assert params[4][0] == "oauth_consumer_key"
    assert params[4][1] == "app_token"
    assert params[5][0] == "oauth_token"
    assert params[5][1] == "" 
开发者ID:evonove,项目名称:mkm-sdk,代码行数:29,代码来源:test_client.py

示例5: test_params_are_unicode

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import Request [as 别名]
def test_params_are_unicode():
    """
    Verifies that parameters are unicode, otherwise
    oauthlib raises a ValueError since they can't be escaped
    """
    client = MKMClient(
        client_key="app_token",
        client_secret="app_secret",
        resource_owner_key="",
        resource_owner_secret="",
        realm="https://sandbox.cardmarket.com",
        nonce="0987654321",
        timestamp="1234567890",
    )

    params = client.get_oauth_params(Request(uri="https://sandbox.cardmarket.com"))

    assert isinstance(params[0][0], six.text_type)
    assert isinstance(params[0][1], six.text_type)
    assert isinstance(params[1][0], six.text_type)
    assert isinstance(params[1][1], six.text_type)
    assert isinstance(params[2][0], six.text_type)
    assert isinstance(params[2][1], six.text_type)
    assert isinstance(params[3][0], six.text_type)
    assert isinstance(params[3][1], six.text_type)
    assert isinstance(params[4][0], six.text_type)
    assert isinstance(params[4][1], six.text_type)
    assert isinstance(params[5][0], six.text_type)
    assert isinstance(params[5][1], six.text_type) 
开发者ID:evonove,项目名称:mkm-sdk,代码行数:31,代码来源:test_client.py

示例6: _create_request

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import Request [as 别名]
def _create_request(self, uri, http_method, body, headers):
        # Only include body data from x-www-form-urlencoded requests
        headers = headers or {}
        if ("Content-Type" in headers and
                CONTENT_TYPE_FORM_URLENCODED in headers["Content-Type"]):
            request = Request(uri, http_method, body, headers)
        else:
            request = Request(uri, http_method, '', headers)

        signature_type, params, oauth_params = (
            self._get_signature_type_and_params(request))

        # The server SHOULD return a 400 (Bad Request) status code when
        # receiving a request with duplicated protocol parameters.
        if len(dict(oauth_params)) != len(oauth_params):
            raise errors.InvalidRequestError(
                description='Duplicate OAuth1 entries.')

        oauth_params = dict(oauth_params)
        request.signature = oauth_params.get('oauth_signature')
        request.client_key = oauth_params.get('oauth_consumer_key')
        request.resource_owner_key = oauth_params.get('oauth_token')
        request.nonce = oauth_params.get('oauth_nonce')
        request.timestamp = oauth_params.get('oauth_timestamp')
        request.redirect_uri = oauth_params.get('oauth_callback')
        request.verifier = oauth_params.get('oauth_verifier')
        request.signature_method = oauth_params.get('oauth_signature_method')
        request.realm = dict(params).get('realm')
        request.oauth_params = oauth_params

        # Parameters to Client depend on signature method which may vary
        # for each request. Note that HMAC-SHA1 and PLAINTEXT share parameters
        request.params = [(k, v) for k, v in params if k != "oauth_signature"]

        if 'realm' in request.headers.get('Authorization', ''):
            request.params = [(k, v)
                              for k, v in request.params if k != "realm"]

        return request 
开发者ID:kylebebak,项目名称:Requester,代码行数:41,代码来源:base.py

示例7: validate_authorization_request

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import Request [as 别名]
def validate_authorization_request(self, uri, http_method='GET', body=None,
                                       headers=None):
        """Extract response_type and route to the designated handler."""
        request = Request(
            uri, http_method=http_method, body=body, headers=headers)

        request.scopes = utils.scope_to_list(request.scope)

        response_type_handler = self.response_types.get(
            request.response_type, self.default_response_type_handler)
        return response_type_handler.validate_authorization_request(request) 
开发者ID:kylebebak,项目名称:Requester,代码行数:13,代码来源:authorization.py

示例8: create_revocation_response

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import Request [as 别名]
def create_revocation_response(self, uri, http_method='POST', body=None,
                                   headers=None):
        """Revoke supplied access or refresh token.


        The authorization server responds with HTTP status code 200 if the
        token has been revoked sucessfully or if the client submitted an
        invalid token.

        Note: invalid tokens do not cause an error response since the client
        cannot handle such an error in a reasonable way.  Moreover, the purpose
        of the revocation request, invalidating the particular token, is
        already achieved.

        The content of the response body is ignored by the client as all
        necessary information is conveyed in the response code.

        An invalid token type hint value is ignored by the authorization server
        and does not influence the revocation response.
        """
        request = Request(
            uri, http_method=http_method, body=body, headers=headers)
        try:
            self.validate_revocation_request(request)
            log.debug('Token revocation valid for %r.', request)
        except OAuth2Error as e:
            log.debug('Client error during validation of %r. %r.', request, e)
            response_body = e.json
            if self.enable_jsonp and request.callback:
                response_body = '%s(%s);' % (request.callback, response_body)
            return {}, response_body, e.status_code

        self.request_validator.revoke_token(request.token,
                                            request.token_type_hint, request)

        response_body = ''
        if self.enable_jsonp and request.callback:
            response_body = request.callback + '();'
        return {}, response_body, 200 
开发者ID:kylebebak,项目名称:Requester,代码行数:41,代码来源:revocation.py

示例9: verify_request

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import Request [as 别名]
def verify_request(self, uri, http_method='GET', body=None, headers=None,
                       scopes=None):
        """Validate client, code etc, return body + headers"""
        request = Request(uri, http_method, body, headers)
        request.token_type = self.find_token_type(request)
        request.scopes = scopes
        token_type_handler = self.tokens.get(request.token_type,
                                             self.default_token_type_handler)
        log.debug('Dispatching token_type %s request to %r.',
                  request.token_type, token_type_handler)
        return token_type_handler.validate_request(request), request 
开发者ID:kylebebak,项目名称:Requester,代码行数:13,代码来源:resource.py

示例10: validate_authorization_request

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import Request [as 别名]
def validate_authorization_request(self, uri, http_method='GET', body=None,
                                       headers=None):
        """Extract response_type and route to the designated handler."""
        request = Request(
            uri, http_method=http_method, body=body, headers=headers)
        request.scopes = None
        response_type_handler = self.response_types.get(
            request.response_type, self.default_response_type_handler)
        return response_type_handler.validate_authorization_request(request) 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:11,代码来源:authorization.py


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