From 4a86fdbd8de57e8482814e5a188c1c7e6b2db42f Mon Sep 17 00:00:00 2001 From: Mona Lisa Date: Thu, 20 Mar 2025 14:36:51 -0400 Subject: [PATCH] Decode the JWT token to get the username and use it in auth field for requests --- pyartifactory/objects/object.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyartifactory/objects/object.py b/pyartifactory/objects/object.py index cb5c9e0..dce231c 100644 --- a/pyartifactory/objects/object.py +++ b/pyartifactory/objects/object.py @@ -8,6 +8,8 @@ import requests from requests import Response +import jwt + from pyartifactory.models import AuthModel @@ -90,7 +92,10 @@ def _generic_http_method_request( headers["Authorization"] = f"Bearer {self._access_token}" kwargs["headers"] = headers - auth = None + decoded_token = jwt.decode(self._access_token, options={"verify_signature": False}) + sub_value = decoded_token.get("sub") + username = sub_value.split('/')[-1] if sub_value else None + auth = (username, self._access_token) else: auth = self._auth