Skip to content

Commit 499f607

Browse files
committed
fix(config): read bearer token once, not twice
1 parent 44dfefb commit 499f607

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

.openapi-generator-templates/configuration.mustache

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,15 +720,19 @@ conf = {{packageName}}.Configuration(
720720
}
721721
{{/isBasicBasic}}
722722
{{#isBasicBearer}}
723-
if self.api_key is not None:
723+
# Resolve the bearer token once: `api_key` is a property that may mint a
724+
# JWT and take the token-manager lock, so a second read would lock twice
725+
# and could race a concurrent `api_key` reset (yielding `Bearer None`).
726+
{{name}}_token = self.api_key
727+
if {{name}}_token is not None:
724728
auth['{{name}}'] = {
725729
'type': 'bearer',
726730
'in': 'header',
727731
{{#bearerFormat}}
728732
'format': '{{.}}',
729733
{{/bearerFormat}}
730734
'key': 'Authorization',
731-
'value': 'Bearer ' + self.api_key
735+
'value': 'Bearer ' + {{name}}_token
732736
}
733737
{{/isBasicBearer}}
734738
{{#isHttpSignature}}

hotdata/configuration.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,16 @@ def auth_settings(self)-> AuthSettings:
571571
:return: The Auth Settings information dict.
572572
"""
573573
auth: AuthSettings = {}
574-
if self.api_key is not None:
574+
# Resolve the bearer token once: `api_key` is a property that may mint a
575+
# JWT and take the token-manager lock, so a second read would lock twice
576+
# and could race a concurrent `api_key` reset (yielding `Bearer None`).
577+
BearerAuth_token = self.api_key
578+
if BearerAuth_token is not None:
575579
auth['BearerAuth'] = {
576580
'type': 'bearer',
577581
'in': 'header',
578582
'key': 'Authorization',
579-
'value': 'Bearer ' + self.api_key
583+
'value': 'Bearer ' + BearerAuth_token
580584
}
581585
if 'WorkspaceId' in self.api_keys:
582586
auth['WorkspaceId'] = {

0 commit comments

Comments
 (0)