當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。