mirror of
https://gitlab.com/octospacc/TelegramIndex-Fork.git
synced 2025-06-05 22:09:12 +02:00
update basic auth check
This commit is contained in:
@@ -10,28 +10,30 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def _do_basic_auth_check(request):
|
def _do_basic_auth_check(request):
|
||||||
|
if "download_" not in request.match_info.route.name:
|
||||||
|
return
|
||||||
|
|
||||||
|
auth = None
|
||||||
auth_header = request.headers.get(hdrs.AUTHORIZATION)
|
auth_header = request.headers.get(hdrs.AUTHORIZATION)
|
||||||
if not auth_header:
|
if auth_header is not None:
|
||||||
if "download_" in request.match_info.route.name:
|
try:
|
||||||
|
auth = BasicAuth.decode(auth_header=auth_header)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if auth is None:
|
||||||
|
try:
|
||||||
|
auth = BasicAuth.from_url(request.url)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not auth:
|
||||||
return Response(
|
return Response(
|
||||||
body=b"",
|
body=b"",
|
||||||
status=401,
|
status=401,
|
||||||
reason="UNAUTHORIZED",
|
reason="UNAUTHORIZED",
|
||||||
headers={
|
headers={hdrs.WWW_AUTHENTICATE: 'Basic realm=""'},
|
||||||
hdrs.WWW_AUTHENTICATE: 'Basic realm=""',
|
|
||||||
hdrs.CONTENT_TYPE: "text/html; charset=utf-8",
|
|
||||||
hdrs.CONNECTION: "keep-alive",
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
auth = BasicAuth.decode(auth_header=auth_header)
|
|
||||||
except ValueError:
|
|
||||||
auth = None
|
|
||||||
|
|
||||||
if not auth:
|
|
||||||
return
|
|
||||||
|
|
||||||
if auth.login is None or auth.password is None:
|
if auth.login is None or auth.password is None:
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user