Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle URL-safe base64 decoding for JWT #38991

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ def wrapper(*args, **kwargs):
)
if _LOGGER.isEnabledFor(logging.DEBUG):
try:
base64_meta_data = token.token.split(".")[1].encode("utf-8") + b"=="
json_bytes = base64.decodebytes(base64_meta_data)
base64_meta_data = token.token.split(".")[1]
padding_needed = 4 - (len(base64_meta_data) % 4)
pvaneck marked this conversation as resolved.
Show resolved Hide resolved
if padding_needed:
base64_meta_data += "=" * padding_needed
json_bytes = base64.urlsafe_b64decode(base64_meta_data)
json_string = json_bytes.decode("utf-8")
json_dict = json.loads(json_string)
upn = json_dict.get("upn", "unavailableUpn")
Expand Down
Loading