本文整理匯總了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)