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


Python Request.grant_type方法代码示例

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


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

示例1: create_token_response

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

        # 'scope' is an allowed Token Request param in both the "Resource Owner Password Credentials Grant"
        # and "Client Credentials Grant" flows
        # https://tools.ietf.org/html/rfc6749#section-4.3.2
        # https://tools.ietf.org/html/rfc6749#section-4.4.2
        request.scopes = utils.scope_to_list(request.scope)

        request.extra_credentials = credentials
        if grant_type_for_scope:
            request.grant_type = grant_type_for_scope

        # OpenID Connect claims, if provided.  The server using oauthlib might choose
        # to implement the claims parameter of the Authorization Request.  In this case
        # it should retrieve those claims and pass them via the claims argument here,
        # as a dict.
        if claims:
            request.claims = claims

        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:ArthurGarnier,项目名称:SickRage,代码行数:32,代码来源:token.py

示例2: create_token_response

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

        # Prioritize grant_type defined as body param over those in uri.
        # Chosen because all three core grant types supply this parameter
        # in the body. However it is not specified explicitely in RFC 6748.
        if 'grant_type' in body_params:
            request.grant_type = query_params.get('grant_type')
        elif 'grant_type' in query_params:
            request.grant_type = body_params.get('grant_type')
        else:
            raise errors.InvalidRequestError(
                description='The grant_type parameter is missing.')

        if not request.grant_type in self.grant_types:
            raise errors.UnsupportedGrantTypeError(
                description='Invalid response type')

        return self.grant_types.get(
                request.grant_type).create_token_response(
                        request, self.default_token)
开发者ID:Chez,项目名称:oauthlib,代码行数:26,代码来源:__init__.py

示例3: test_validate_token_request

# 需要导入模块: from oauthlib.common import Request [as 别名]
# 或者: from oauthlib.common.Request import grant_type [as 别名]
    def test_validate_token_request(self):
        mock_validator = mock.MagicMock()
        auth = AuthorizationCodeGrant(request_validator=mock_validator)
        request = Request('http://a.b/path')
        self.assertRaises(UnsupportedGrantTypeError,
                auth.validate_token_request, request)

        request.grant_type = 'authorization_code'
        self.assertRaises(InvalidRequestError,
                auth.validate_token_request, request)

        mock_validator.validate_client = mock.MagicMock(return_value=False)
        request.code = 'waffles'
        request.client = 'batman'
        self.assertRaises(UnauthorizedClientError,
                auth.validate_token_request, request)

        mock_validator.validate_client = mock.MagicMock(return_value=True)
        mock_validator.validate_code = mock.MagicMock(return_value=False)
        self.assertRaises(InvalidGrantError,
                auth.validate_token_request, request)
开发者ID:Chez,项目名称:oauthlib,代码行数:23,代码来源:test_grant_types.py

示例4: create_token_response

# 需要导入模块: from oauthlib.common import Request [as 别名]
# 或者: from oauthlib.common.Request import grant_type [as 别名]
    def create_token_response(self, uri, http_method='GET', body=None,
                              headers=None, credentials=None, grant_type_for_scope=None,
                              claims=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
        if grant_type_for_scope:
            request.grant_type = grant_type_for_scope

        # OpenID Connect claims, if provided.  The server using oauthlib might choose
        # to implement the claims parameter of the Authorization Request.  In this case
        # it should retrieve those claims and pass them via the claims argument here,
        # as a dict.
        if claims:
            request.claims = claims

        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:DevStarSJ,项目名称:Study,代码行数:26,代码来源:token.py


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