Skip to content

Commit f62e58d

Browse files
authored
Decode the JWT token to get the username and use it in auth field for requests
1 parent 1f05a4c commit f62e58d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

pyartifactory/objects/object.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import requests
99
from requests import Response
1010

11+
import jwt
12+
1113
from pyartifactory.models import AuthModel
1214

1315

@@ -90,7 +92,10 @@ def _generic_http_method_request(
9092
headers["Authorization"] = f"Bearer {self._access_token}"
9193
kwargs["headers"] = headers
9294

93-
auth = None
95+
decoded_token = jwt.decode(self._access_token, options={"verify_signature": False})
96+
sub_value = decoded_token.get("sub")
97+
username = sub_value.split('/')[-1] if sub_value else None
98+
auth = (username, self._access_token)
9499
else:
95100
auth = self._auth
96101

0 commit comments

Comments
 (0)