Skip to content

Commit fdfb681

Browse files
committed
fix(auth): call 'load_configs()' to load auth infos from '.docker/config.json'.
- Enhance token request logging and authentication logic - Update registry manifest retrieval to ensure proper authentication - Improve error handling in authentication utils
1 parent 17e3dae commit fdfb681

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

oras/auth/token.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,14 @@ def request_token(self, h: auth_utils.authHeader) -> bool:
124124
logger.debug(f"Scope: {h.scope}")
125125
params["scope"] = h.scope
126126

127-
# Set Basic Auth to receive token
128-
headers["Authorization"] = "Basic %s" % self._basic_auth
129-
130-
logger.debug(f"Requesting auth token for: {h}")
127+
# Set Basic Auth to receive token, if available
128+
if hasattr(self, "_basic_auth") and self._basic_auth:
129+
headers["Authorization"] = "Basic %s" % self._basic_auth
130+
logger.debug("Using Basic Auth for token request.")
131+
else:
132+
logger.debug("No Basic Auth available or configured for token request. Proceeding without Basic Auth header for token endpoint.")
133+
134+
logger.debug(f"Requesting auth token for: {h} with header keys: {list(headers.keys())}")
131135
authResponse = self.session.get(h.realm, headers=headers, params=params, verify=self._tls_verify) # type: ignore
132136

133137
if authResponse.status_code != 200:

oras/auth/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def load_configs(configs: Optional[List[str]] = None):
3434
continue
3535
cfg = oras.utils.read_json(config)
3636
auths.update(cfg.get("auths", {}))
37+
3738
return auths
3839

3940

oras/provider.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,12 +946,17 @@ def get_manifest(
946946
:param allowed_media_type: one or more allowed media types
947947
:type allowed_media_type: str
948948
"""
949+
# Load authentication configs for the container's registry
950+
# This ensures credentials are available for authenticated registries
951+
self.auth.load_configs(container)
952+
949953
if not allowed_media_type:
950954
allowed_media_type = [oras.defaults.default_manifest_media_type]
951955
headers = {"Accept": ";".join(allowed_media_type)}
952956

953957
get_manifest = f"{self.prefix}://{container.manifest_url()}" # type: ignore
954958
response = self.do_request(get_manifest, "GET", headers=headers)
959+
955960
self._check_200_response(response)
956961
manifest = response.json()
957962
jsonschema.validate(manifest, schema=oras.schemas.manifest)

0 commit comments

Comments
 (0)