Skip to content

Commit e164a49

Browse files
committed
implement review comment about anon/req token
from: oras-project#148 (comment) > And if the basic auth is there, skip over asking for an anon token as it stands, in case the basic auth are present, these are exchanged for the request token. Signed-off-by: tarilabs <matteo.mortari@gmail.com>
1 parent 23ee55a commit e164a49

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ env
77
__pycache__
88
.python-version
99
.venv
10+
.vscode
11+
build
12+
dist

oras/auth/token.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,18 @@ def authenticate_request(
7171

7272
h = auth_utils.parse_auth_header(authHeaderRaw)
7373

74-
# First try to request an anonymous token
75-
logger.debug("No Authorization, requesting anonymous token")
76-
anon_token = self.request_anonymous_token(h)
77-
if anon_token:
78-
logger.debug("Successfully obtained anonymous token!")
79-
self.token = anon_token
80-
headers["Authorization"] = "Bearer %s" % self.token
81-
return headers, True
82-
83-
# Next try for logged in token
74+
# if no basic auth, try by request an anonymous token
75+
if not hasattr(self, '_basic_auth'):
76+
logger.debug("No Basic Auth found, requesting anonymous token")
77+
anon_token = self.request_anonymous_token(h)
78+
if anon_token:
79+
logger.debug("Successfully obtained anonymous token!")
80+
self.token = anon_token
81+
headers["Authorization"] = "Bearer %s" % self.token
82+
return headers, True
83+
84+
# try using auth token
85+
logger.debug("requesting Auth Token")
8486
token = self.request_token(h)
8587
if token:
8688
self.token = token

0 commit comments

Comments
 (0)