def _validate_http_auth(self):
"""Verify http auth request with values in "Authorization" header
"""
if not self.key or not self.secret:
return True
try:
auth_type, encoded_auth_str = \
request.headers['Authorization'].split(' ', 1)
if auth_type == 'Basic':
decoded_auth_str = base64.decodestring(encoded_auth_str)
auth_id, auth_token = decoded_auth_str.split(':', 1)
if auth_id == self.key and auth_token == self.secret:
return True
except (KeyError, ValueError, TypeError):
pass
raise Unauthorized("HTTP Auth Failed")
评论列表
文章目录