Skip to content

Commit 247ef7a

Browse files
Merge pull request #33 from containers/1.0-auth-fix
fix(auth): do auth dance even when basic auth creds are not found
2 parents 2929999 + 09d9a4b commit 247ef7a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

image/client.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def get_auth_token(
139139
response, and MUST include the www-authenticate header
140140
141141
Args:
142-
res (Type[requests.Response]): The response from the registry API
142+
res (requests.Response): The response from the registry API
143143
reg_auth (str): The auth retrieved for the registry
144144
145145
Returns:
@@ -168,9 +168,11 @@ def get_auth_token(
168168

169169
# Send the request to the auth service, parse the token from the
170170
# response
171-
headers = {
172-
'Authorization': f"Basic {reg_auth}"
173-
}
171+
headers = {}
172+
if len(reg_auth) > 0:
173+
headers = {
174+
'Authorization': f"Basic {reg_auth}"
175+
}
174176
token_res = requests.get(auth_url, headers=headers)
175177
token_res.raise_for_status()
176178
token_json = token_res.json()
@@ -219,7 +221,7 @@ def query_blob(
219221
# Send the request to the distribution registry API
220222
# If it fails with a 401 response code and auth given, do OAuth dance
221223
res = requests.get(api_url, headers=headers)
222-
if res.status_code == 401 and found and \
224+
if res.status_code == 401 and \
223225
'www-authenticate' in res.headers.keys():
224226
# Do Oauth dance if basic auth fails
225227
# Ref: https://distribution.github.io/distribution/spec/auth/token/
@@ -308,7 +310,7 @@ def query_manifest(
308310
# Send the request to the distribution registry API
309311
# If it fails with a 401 response code and auth given, do OAuth dance
310312
res = requests.get(api_url, headers=headers)
311-
if res.status_code == 401 and found and \
313+
if res.status_code == 401 and \
312314
'www-authenticate' in res.headers.keys():
313315
# Do Oauth dance if basic auth fails
314316
# Ref: https://distribution.github.io/distribution/spec/auth/token/
@@ -433,7 +435,7 @@ def delete(
433435
# Send the request to the distribution registry API
434436
# If it fails with a 401 response code and auth given, do OAuth dance
435437
res = requests.delete(api_url, headers=headers)
436-
if res.status_code == 401 and found and \
438+
if res.status_code == 401 and \
437439
'www-authenticate' in res.headers.keys():
438440
# Do Oauth dance if basic auth fails
439441
# Ref: https://distribution.github.io/distribution/spec/auth/token/

0 commit comments

Comments
 (0)