本文整理汇总了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
示例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")
示例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
示例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
示例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