Skip to content

Commit 6d1f4c6

Browse files
committed
Fixed cookies authentication
1 parent 44906a3 commit 6d1f4c6

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

fix_cookies.patch

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
diff --git a/swagger_client/api_client.py b/swagger_client/api_client.py
2+
index 850cf27..01eb57b 100644
3+
--- a/swagger_client/api_client.py
4+
+++ b/swagger_client/api_client.py
5+
@@ -500,9 +500,14 @@ class ApiClient(object):
6+
headers[auth_setting['key']] = auth_setting['value']
7+
elif auth_setting['in'] == 'query':
8+
querys.append((auth_setting['key'], auth_setting['value']))
9+
+ elif auth_setting["in"] == "cookie":
10+
+ cookies = headers.get("Cookie", "")
11+
+ cookies = cookies + "; " if cookies else ""
12+
+ cookies += f"{auth_setting['key']}={auth_setting['value']}"
13+
+ headers["Cookie"] = cookies
14+
else:
15+
raise ValueError(
16+
- 'Authentication token must be in `query` or `header`'
17+
+ 'Authentication token must be in `query`, `cookie` or `header`'
18+
)
19+
20+
def __deserialize_file(self, response):
21+
diff --git a/swagger_client/configuration.py b/swagger_client/configuration.py
22+
index f845017..bc25823 100644
23+
--- a/swagger_client/configuration.py
24+
+++ b/swagger_client/configuration.py
25+
@@ -232,14 +232,14 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
26+
'cookieCSRF':
27+
{
28+
'type': 'api_key',
29+
- 'in': 'query',
30+
+ 'in': 'cookie',
31+
'key': 'csrftoken',
32+
'value': self.get_api_key_with_prefix('csrftoken')
33+
},
34+
'cookieSession':
35+
{
36+
'type': 'api_key',
37+
- 'in': 'query',
38+
+ 'in': 'cookie',
39+
'key': 'LEETCODE_SESSION',
40+
'value': self.get_api_key_with_prefix('LEETCODE_SESSION')
41+
},

swagger_client/api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,14 @@ def update_params_for_auth(self, headers, querys, auth_settings):
500500
headers[auth_setting['key']] = auth_setting['value']
501501
elif auth_setting['in'] == 'query':
502502
querys.append((auth_setting['key'], auth_setting['value']))
503+
elif auth_setting["in"] == "cookie":
504+
cookies = headers.get("Cookie", "")
505+
cookies = cookies + "; " if cookies else ""
506+
cookies += f"{auth_setting['key']}={auth_setting['value']}"
507+
headers["Cookie"] = cookies
503508
else:
504509
raise ValueError(
505-
'Authentication token must be in `query` or `header`'
510+
'Authentication token must be in `query`, `cookie` or `header`'
506511
)
507512

508513
def __deserialize_file(self, response):

swagger_client/configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ def auth_settings(self):
232232
'cookieCSRF':
233233
{
234234
'type': 'api_key',
235-
'in': 'query',
235+
'in': 'cookie',
236236
'key': 'csrftoken',
237237
'value': self.get_api_key_with_prefix('csrftoken')
238238
},
239239
'cookieSession':
240240
{
241241
'type': 'api_key',
242-
'in': 'query',
242+
'in': 'cookie',
243243
'key': 'LEETCODE_SESSION',
244244
'value': self.get_api_key_with_prefix('LEETCODE_SESSION')
245245
},

0 commit comments

Comments
 (0)