Skip to content

Commit b36bcc9

Browse files
authored
Merge pull request #12212 from corytodd/fix-python-config-basic-auth
[python] Fix basic auth always being used
2 parents dc5f58b + b1ca1b5 commit b36bcc9

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

modules/swagger-codegen/src/main/resources/python/configuration.mustache

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,12 @@ class Configuration(object):
216216

217217
:return: The token for basic HTTP authentication.
218218
"""
219-
return urllib3.util.make_headers(
220-
basic_auth=self.username + ':' + self.password
221-
).get('authorization')
219+
token = ""
220+
if self.username or self.password:
221+
token = urllib3.util.make_headers(
222+
basic_auth=self.username + ':' + self.password
223+
).get('authorization')
224+
return token
222225

223226
def auth_settings(self):
224227
"""Gets Auth Settings dict for api client.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.9-SNAPSHOT
1+
2.4.33-SNAPSHOT

samples/client/petstore-security-test/python/petstore_api/configuration.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,12 @@ def get_basic_auth_token(self):
214214
215215
:return: The token for basic HTTP authentication.
216216
"""
217-
return urllib3.util.make_headers(
218-
basic_auth=self.username + ':' + self.password
219-
).get('authorization')
217+
token = ""
218+
if self.username or self.password:
219+
token = urllib3.util.make_headers(
220+
basic_auth=self.username + ':' + self.password
221+
).get('authorization')
222+
return token
220223

221224
def auth_settings(self):
222225
"""Gets Auth Settings dict for api client.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.20-SNAPSHOT
1+
2.4.33-SNAPSHOT

samples/client/petstore/python/petstore_api/configuration.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,12 @@ def get_basic_auth_token(self):
225225
226226
:return: The token for basic HTTP authentication.
227227
"""
228-
return urllib3.util.make_headers(
229-
basic_auth=self.username + ':' + self.password
230-
).get('authorization')
228+
token = ""
229+
if self.username or self.password:
230+
token = urllib3.util.make_headers(
231+
basic_auth=self.username + ':' + self.password
232+
).get('authorization')
233+
return token
231234

232235
def auth_settings(self):
233236
"""Gets Auth Settings dict for api client.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# coding: utf-8

0 commit comments

Comments
 (0)