def add_basic_auth(blueprint, username, password, realm='RQ Scheduler Dashboard'):
"""Add HTTP Basic Auth to a blueprint.
Note this is only for casual use!
"""
@blueprint.before_request
def basic_http_auth(*args, **kwargs):
auth = request.authorization
if (
auth is None
or auth.password != password
or auth.username != username):
return Response(
'Please login',
401,
{'WWW-Authenticate': 'Basic realm="{}"'.format(realm)})
评论列表
文章目录