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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ def wrapper(*args, **kwargs):
try:
token = fn(*args, **kwargs)
_LOGGER.log(
logging.DEBUG if within_credential_chain.get() else logging.INFO, "%s succeeded", fn.__qualname__
logging.DEBUG if within_credential_chain.get() else logging.INFO,
"%s succeeded",
fn.__qualname__,
)
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 = -len(base64_meta_data) % 4
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ async def wrapper(*args, **kwargs):
try:
token = await fn(*args, **kwargs)
_LOGGER.log(
logging.DEBUG if within_credential_chain.get() else logging.INFO, "%s succeeded", fn.__qualname__
logging.DEBUG if within_credential_chain.get() else logging.INFO,
"%s succeeded",
fn.__qualname__,
)
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 = -len(base64_meta_data) % 4
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