|
34 | 34 | Catalog, |
35 | 35 | Identifier, |
36 | 36 | Properties, |
37 | | - PropertiesUpdateSummary, |
| 37 | + PropertiesUpdateSummary, TOKEN, |
38 | 38 | ) |
39 | 39 | from pyiceberg.exceptions import ( |
40 | 40 | AuthorizationExpiredError, |
@@ -87,7 +87,6 @@ class Endpoints: |
87 | 87 | CREDENTIAL = "credential" |
88 | 88 | GRANT_TYPE = "grant_type" |
89 | 89 | SCOPE = "scope" |
90 | | -TOKEN = "token" |
91 | 90 | TOKEN_EXCHANGE = "urn:ietf:params:oauth:grant-type:token-exchange" |
92 | 91 | SEMICOLON = ":" |
93 | 92 | KEY = "key" |
@@ -206,12 +205,13 @@ def _create_session(self) -> None: |
206 | 205 | elif ssl_client_cert := ssl_client.get(CERT): |
207 | 206 | self.session.cert = ssl_client_cert |
208 | 207 |
|
| 208 | + # If we have credentials, but not a token, we want to fetch a token |
| 209 | + if TOKEN not in self.properties and CREDENTIAL in self.properties: |
| 210 | + self.properties[TOKEN] = self._fetch_access_token(self.properties[CREDENTIAL]) |
| 211 | + |
209 | 212 | # Set Auth token for subsequent calls in the session |
210 | 213 | if token := self.properties.get(TOKEN): |
211 | 214 | self.session.headers[AUTHORIZATION_HEADER] = f"{BEARER_PREFIX} {token}" |
212 | | - elif credential := self.properties.get(CREDENTIAL): |
213 | | - token = self._fetch_access_token(credential) |
214 | | - self.session.headers[AUTHORIZATION_HEADER] = f"{BEARER_PREFIX} {token}" |
215 | 215 |
|
216 | 216 | # Set HTTP headers |
217 | 217 | self.session.headers["Content-type"] = "application/json" |
|
0 commit comments