1
0
mirror of https://github.com/quay/quay.git synced 2026-01-27 18:42:52 +03:00
Files
quay/util/headers.py
2019-12-02 12:23:08 -05:00

22 lines
504 B
Python

import base64
def parse_basic_auth(header_value):
""" Attempts to parse the given header value as a Base64-encoded Basic auth header. """
if not header_value:
return None
parts = header_value.split(" ")
if len(parts) != 2 or parts[0].lower() != "basic":
return None
try:
basic_parts = base64.b64decode(parts[1]).split(":", 1)
if len(basic_parts) != 2:
return None
return basic_parts
except ValueError:
return None