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


Python httpexceptions.HTTPUnauthorized方法代码示例

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


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

示例1: _check_signature

# 需要导入模块: from pyramid import httpexceptions [as 别名]
# 或者: from pyramid.httpexceptions import HTTPUnauthorized [as 别名]
def _check_signature(self, request, key):
        """Check the Hawk auth signature on the request.

        This method checks the Hawk signature on the request against the
        supplied signing key.  If missing or invalid then HTTPUnauthorized
        is raised.

        The TokenServerAuthenticationPolicy implementation wraps the default
        HawkAuthenticationPolicy implementation with some logging.
        """
        supercls = super(TokenServerAuthenticationPolicy, self)
        try:
            return supercls._check_signature(request, key)
        except HTTPUnauthorized:
            logger.warn("Authentication Failed: invalid hawk signature")
            raise 
开发者ID:mozilla-services,项目名称:shavar,代码行数:18,代码来源:__init__.py

示例2: test_that_hawkauth_is_used_by_default

# 需要导入模块: from pyramid import httpexceptions [as 别名]
# 或者: from pyramid.httpexceptions import HTTPUnauthorized [as 别名]
def test_that_hawkauth_is_used_by_default(self):
        # Generate signed request.
        req = self.make_request()
        tokenid, key = self.policy.encode_hawk_id(req, 42)
        hawkauthlib.sign_request(req, tokenid, key)
        # That should be enough to authenticate.
        self.assertEqual(req.authenticated_userid, 42)
        self.assertEqual(req.user.get("uid"), 42)
        # Check that it rejects invalid Hawk ids.
        req = self.make_request()
        hawkauthlib.sign_request(req, tokenid, key)
        authz = req.environ["HTTP_AUTHORIZATION"]
        req.environ["HTTP_AUTHORIZATION"] = authz.replace(tokenid, "XXXXXX")
        with self.assertRaises(HTTPUnauthorized):
            req.authenticated_userid
        # And that the rejection gets raised when accessing request.user
        self.assertRaises(HTTPUnauthorized, getattr, req, "user") 
开发者ID:mozilla-services,项目名称:shavar,代码行数:19,代码来源:test_user.py

示例3: test_checking_of_token_node_assignment

# 需要导入模块: from pyramid import httpexceptions [as 别名]
# 或者: from pyramid.httpexceptions import HTTPUnauthorized [as 别名]
def test_checking_of_token_node_assignment(self):
        # Generate a token for one node
        req = self.make_request(environ={
            "HTTP_HOST": "host1.com",
        })
        tokenid, key = self.policy.encode_hawk_id(req, 42)
        # It can authenticate for requests to that node.
        hawkauthlib.sign_request(req, tokenid, key)
        self.assertEqual(req.authenticated_userid, 42)
        self.assertEqual(req.user.get("uid"), 42)
        # But not requests to some other node.
        req = self.make_request(environ={
            "HTTP_HOST": "host2.com",
        })
        hawkauthlib.sign_request(req, tokenid, key)
        with self.assertRaises(HTTPUnauthorized):
            req.authenticated_userid 
开发者ID:mozilla-services,项目名称:shavar,代码行数:19,代码来源:test_user.py

示例4: graphqlview

# 需要导入模块: from pyramid import httpexceptions [as 别名]
# 或者: from pyramid.httpexceptions import HTTPUnauthorized [as 别名]
def graphqlview(context, request):  #pylint: disable=W0613
    token = request.headers.get('X-Api-Key', '')
    is_private = getattr(request.root, 'only_for_members', False)
    if is_private and not auth_user(token, request):
        response = HTTPUnauthorized()
        response.content_type = 'application/json'
        return response

    if request.method == 'OPTIONS':
        response = Response(status=200, body=b'')
        response.headerlist = []  # we have to reset headerlist
        response.headerlist.extend(
            (
                ('Access-Control-Allow-Origin', '*'),
                ('Access-Control-Allow-Headers', 'Content-Type'),
            )
        )
    else:
        solver = graphql_wsgi(schema)
        response = solver(request)
        response.headerlist.append(
            ('Access-Control-Allow-Origin', '*')
        )

    return response 
开发者ID:ecreall,项目名称:nova-ideo,代码行数:27,代码来源:views.py

示例5: listen

# 需要导入模块: from pyramid import httpexceptions [as 别名]
# 或者: from pyramid.httpexceptions import HTTPUnauthorized [as 别名]
def listen(request):
    """
    Handles long polling connections
    ---
    get:
      tags:
      - "Client API"
      summary: "Handles long polling connections"
      description: ""
      operationId: "listen"
      produces:
      - "application/json"
      responses:
        200:
          description: "Success"
    """
    server_state = get_state()
    config = request.registry.settings
    conn_id = utils.uuid_from_string(request.params.get("conn_id"))
    connection = server_state.connections.get(conn_id)
    if not connection:
        raise HTTPUnauthorized()
    # attach a queue to connection
    connection.queue = Queue()
    connection.deliver_catchup_messages()
    request.response.app_iter = yield_response(request, connection, config)
    return request.response 
开发者ID:Channelstream,项目名称:channelstream,代码行数:29,代码来源:server.py


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