本文整理汇总了Python中flask_httpauth.HTTPBasicAuth方法的典型用法代码示例。如果您正苦于以下问题:Python flask_httpauth.HTTPBasicAuth方法的具体用法?Python flask_httpauth.HTTPBasicAuth怎么用?Python flask_httpauth.HTTPBasicAuth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_httpauth
的用法示例。
在下文中一共展示了flask_httpauth.HTTPBasicAuth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_extensions
# 需要导入模块: import flask_httpauth [as 别名]
# 或者: from flask_httpauth import HTTPBasicAuth [as 别名]
def register_extensions(self):
self.auth = HTTPBasicAuth()
self.csrf = CSRFProtect()
self.csrf.init_app(self)
示例2: setup_http_basic_auth
# 需要导入模块: import flask_httpauth [as 别名]
# 或者: from flask_httpauth import HTTPBasicAuth [as 别名]
def setup_http_basic_auth(self):
auth = HTTPBasicAuth()
self.verify_password = auth.verify_password(self.verify_password)
return auth
示例3: __init__
# 需要导入模块: import flask_httpauth [as 别名]
# 或者: from flask_httpauth import HTTPBasicAuth [as 别名]
def __init__(self, source):
self.auth = HTTPBasicAuth()
self.source = source
@self.auth.verify_password
def verify_password(username, password):
for user in self.source.users:
if user.username == username:
return check_password_hash(user.password, password)
return False
@self.auth.error_handler
def unauthorized():
# return 403 instead of 401 to prevent browsers from displaying the default
# auth dialog
return make_response(jsonify({'message': 'Unauthorized access'}), 403)
self.second_auth = HTTPTokenAuth()
@self.second_auth.verify_token
def verify_token(token):
self.clean_tokens()
headers = request.headers
token = headers.get("X-Api-Key")
for user in self.source.users:
for current_token in user.tokens:
if user.tokens[current_token][0] == token:
return True
return False
@self.second_auth.error_handler
def unauthorized():
# return 403 instead of 401 to prevent browsers from displaying the default
# auth dialog
return make_response(jsonify({'message': 'Unauthorized access'}), 403)