Skip to content

Commit f190cf6

Browse files
committed
fix connection logic
1 parent 20deff4 commit f190cf6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

inventree/api.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ def connect(self):
137137
except Exception:
138138
raise ConnectionRefusedError("Could not connect to InvenTree server")
139139

140+
if self.use_oidc_auth:
141+
self.requestOidcToken()
142+
return
143+
140144
# Basic authentication
141145
self.auth = HTTPBasicAuth(self.username, self.password)
142146

@@ -145,8 +149,6 @@ def connect(self):
145149

146150
if self.use_token_auth and not self.token:
147151
self.requestToken()
148-
elif self.use_oidc_auth and not self.token:
149-
self.requestOidcToken()
150152

151153
def constructApiUrl(self, endpoint_url):
152154
"""Construct an API endpoint URL based on the provided API URL.
@@ -335,9 +337,12 @@ def request(self, api_url, **kwargs):
335337
'timeout': kwargs.get('timeout', self.timeout),
336338
}
337339

338-
if (self.use_token_auth or self.use_oidc_auth) and self.token:
340+
if self.use_token_auth and self.token:
339341
headers['AUTHORIZATION'] = f'Token {self.token}'
340342
auth = None
343+
elif self.use_oidc_auth and self.token:
344+
headers['AUTHORIZATION'] = f'Bearer {self.token}'
345+
auth = None
341346
else:
342347
auth = self.auth
343348

0 commit comments

Comments
 (0)