Skip to content

Commit 561e193

Browse files
authored
Add descope project ID header (#557)
1 parent 2ca007b commit 561e193

26 files changed

+213
-1
lines changed

descope/auth.py

+1
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ def generate_jwt_response(
560560

561561
def _get_default_headers(self, pswd: str | None = None):
562562
headers = _default_headers.copy()
563+
headers["x-descope-project-id"] = self.project_id
563564
bearer = self.project_id
564565
if pswd:
565566
bearer = f"{self.project_id}:{pswd}"

tests/management/test_access_key.py

+7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def test_create(self):
6868
headers={
6969
**common.default_headers,
7070
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
71+
"x-descope-project-id": self.dummy_project_id,
7172
},
7273
params=None,
7374
json={
@@ -119,6 +120,7 @@ def test_load(self):
119120
headers={
120121
**common.default_headers,
121122
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
123+
"x-descope-project-id": self.dummy_project_id,
122124
},
123125
params={"id": "key-id"},
124126
allow_redirects=None,
@@ -161,6 +163,7 @@ def test_search_all_users(self):
161163
headers={
162164
**common.default_headers,
163165
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
166+
"x-descope-project-id": self.dummy_project_id,
164167
},
165168
params=None,
166169
json={
@@ -202,6 +205,7 @@ def test_update(self):
202205
headers={
203206
**common.default_headers,
204207
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
208+
"x-descope-project-id": self.dummy_project_id,
205209
},
206210
params=None,
207211
json={
@@ -240,6 +244,7 @@ def test_deactivate(self):
240244
headers={
241245
**common.default_headers,
242246
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
247+
"x-descope-project-id": self.dummy_project_id,
243248
},
244249
params=None,
245250
json={
@@ -276,6 +281,7 @@ def test_activate(self):
276281
headers={
277282
**common.default_headers,
278283
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
284+
"x-descope-project-id": self.dummy_project_id,
279285
},
280286
params=None,
281287
json={
@@ -312,6 +318,7 @@ def test_delete(self):
312318
headers={
313319
**common.default_headers,
314320
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
321+
"x-descope-project-id": self.dummy_project_id,
315322
},
316323
params=None,
317324
json={

tests/management/test_audit.py

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def test_search(self):
7373
headers={
7474
**common.default_headers,
7575
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
76+
"x-descope-project-id": self.dummy_project_id,
7677
},
7778
params=None,
7879
json={"noTenants": False},
@@ -115,6 +116,7 @@ def test_create_event(self):
115116
headers={
116117
**common.default_headers,
117118
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
119+
"x-descope-project-id": self.dummy_project_id,
118120
},
119121
params=None,
120122
json={

tests/management/test_authz.py

+17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def test_save_schema(self):
4444
headers={
4545
**common.default_headers,
4646
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
47+
"x-descope-project-id": self.dummy_project_id,
4748
},
4849
params=None,
4950
json={"schema": {"name": "kuku"}, "upgrade": True},
@@ -74,6 +75,7 @@ def test_delete_schema(self):
7475
headers={
7576
**common.default_headers,
7677
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
78+
"x-descope-project-id": self.dummy_project_id,
7779
},
7880
params=None,
7981
json=None,
@@ -104,6 +106,7 @@ def test_load_schema(self):
104106
headers={
105107
**common.default_headers,
106108
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
109+
"x-descope-project-id": self.dummy_project_id,
107110
},
108111
params=None,
109112
json=None,
@@ -136,6 +139,7 @@ def test_save_namespace(self):
136139
headers={
137140
**common.default_headers,
138141
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
142+
"x-descope-project-id": self.dummy_project_id,
139143
},
140144
params=None,
141145
json={
@@ -170,6 +174,7 @@ def test_delete_namespace(self):
170174
headers={
171175
**common.default_headers,
172176
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
177+
"x-descope-project-id": self.dummy_project_id,
173178
},
174179
params=None,
175180
json={"name": "a", "schemaName": "b"},
@@ -206,6 +211,7 @@ def test_save_relation_definition(self):
206211
headers={
207212
**common.default_headers,
208213
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
214+
"x-descope-project-id": self.dummy_project_id,
209215
},
210216
params=None,
211217
json={
@@ -245,6 +251,7 @@ def test_delete_relation_definition(self):
245251
headers={
246252
**common.default_headers,
247253
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
254+
"x-descope-project-id": self.dummy_project_id,
248255
},
249256
params=None,
250257
json={"name": "a", "namespace": "b", "schemaName": "c"},
@@ -286,6 +293,7 @@ def test_create_relations(self):
286293
headers={
287294
**common.default_headers,
288295
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
296+
"x-descope-project-id": self.dummy_project_id,
289297
},
290298
params=None,
291299
json={
@@ -336,6 +344,7 @@ def test_delete_relations(self):
336344
headers={
337345
**common.default_headers,
338346
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
347+
"x-descope-project-id": self.dummy_project_id,
339348
},
340349
params=None,
341350
json={
@@ -377,6 +386,7 @@ def test_delete_relations_for_resources(self):
377386
headers={
378387
**common.default_headers,
379388
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
389+
"x-descope-project-id": self.dummy_project_id,
380390
},
381391
params=None,
382392
json={"resources": ["r"]},
@@ -418,6 +428,7 @@ def test_has_relations(self):
418428
headers={
419429
**common.default_headers,
420430
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
431+
"x-descope-project-id": self.dummy_project_id,
421432
},
422433
params=None,
423434
json={
@@ -459,6 +470,7 @@ def test_who_can_access(self):
459470
headers={
460471
**common.default_headers,
461472
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
473+
"x-descope-project-id": self.dummy_project_id,
462474
},
463475
params=None,
464476
json={"resource": "a", "relationDefinition": "b", "namespace": "c"},
@@ -489,6 +501,7 @@ def test_resource_relations(self):
489501
headers={
490502
**common.default_headers,
491503
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
504+
"x-descope-project-id": self.dummy_project_id,
492505
},
493506
params=None,
494507
json={"resource": "a"},
@@ -519,6 +532,7 @@ def test_targets_relations(self):
519532
headers={
520533
**common.default_headers,
521534
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
535+
"x-descope-project-id": self.dummy_project_id,
522536
},
523537
params=None,
524538
json={"targets": ["a"]},
@@ -551,6 +565,7 @@ def test_what_can_target_access(self):
551565
headers={
552566
**common.default_headers,
553567
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
568+
"x-descope-project-id": self.dummy_project_id,
554569
},
555570
params=None,
556571
json={"target": "a"},
@@ -589,6 +604,7 @@ def test_what_can_target_access_with_relation(self):
589604
headers={
590605
**common.default_headers,
591606
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
607+
"x-descope-project-id": self.dummy_project_id,
592608
},
593609
params=None,
594610
json={"target": "a", "relationDefinition": "b", "namespace": "c"},
@@ -619,6 +635,7 @@ def test_get_modified(self):
619635
headers={
620636
**common.default_headers,
621637
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
638+
"x-descope-project-id": self.dummy_project_id,
622639
},
623640
params=None,
624641
json={"since": 0},

tests/management/test_fga.py

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def test_save_schema(self):
4444
headers={
4545
**common.default_headers,
4646
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
47+
"x-descope-project-id": self.dummy_project_id,
4748
},
4849
params=None,
4950
json={"dsl": "model AuthZ 1.0"},
@@ -86,6 +87,7 @@ def test_create_relations(self):
8687
headers={
8788
**common.default_headers,
8889
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
90+
"x-descope-project-id": self.dummy_project_id,
8991
},
9092
params=None,
9193
json={
@@ -138,6 +140,7 @@ def test_delete_relations(self):
138140
headers={
139141
**common.default_headers,
140142
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
143+
"x-descope-project-id": self.dummy_project_id,
141144
},
142145
params=None,
143146
json={
@@ -190,6 +193,7 @@ def test_check(self):
190193
headers={
191194
**common.default_headers,
192195
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
196+
"x-descope-project-id": self.dummy_project_id,
193197
},
194198
params=None,
195199
json={

tests/management/test_flow.py

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def test_list_flows(self):
4747
headers={
4848
**common.default_headers,
4949
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
50+
"x-descope-project-id": self.dummy_project_id,
5051
},
5152
params=None,
5253
json=None,
@@ -81,6 +82,7 @@ def test_delete_flows(self):
8182
headers={
8283
**common.default_headers,
8384
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
85+
"x-descope-project-id": self.dummy_project_id,
8486
},
8587
params=None,
8688
json={"ids": ["flow-1", "flow-2"]},
@@ -115,6 +117,7 @@ def test_export_flow(self):
115117
headers={
116118
**common.default_headers,
117119
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
120+
"x-descope-project-id": self.dummy_project_id,
118121
},
119122
params=None,
120123
json={
@@ -155,6 +158,7 @@ def test_import_flow(self):
155158
headers={
156159
**common.default_headers,
157160
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
161+
"x-descope-project-id": self.dummy_project_id,
158162
},
159163
params=None,
160164
json={
@@ -189,6 +193,7 @@ def test_export_theme(self):
189193
headers={
190194
**common.default_headers,
191195
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
196+
"x-descope-project-id": self.dummy_project_id,
192197
},
193198
params=None,
194199
json={},
@@ -221,6 +226,7 @@ def test_import_theme(self):
221226
headers={
222227
**common.default_headers,
223228
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
229+
"x-descope-project-id": self.dummy_project_id,
224230
},
225231
params=None,
226232
json={"theme": {"id": "test"}},

tests/management/test_group.py

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_load_all_groups(self):
4848
headers={
4949
**common.default_headers,
5050
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
51+
"x-descope-project-id": self.dummy_project_id,
5152
},
5253
params=None,
5354
json={
@@ -88,6 +89,7 @@ def test_load_all_groups_for_members(self):
8889
headers={
8990
**common.default_headers,
9091
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
92+
"x-descope-project-id": self.dummy_project_id,
9193
},
9294
params=None,
9395
json={
@@ -129,6 +131,7 @@ def test_load_all_group_members(self):
129131
headers={
130132
**common.default_headers,
131133
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
134+
"x-descope-project-id": self.dummy_project_id,
132135
},
133136
params=None,
134137
json={

tests/management/test_jwt.py

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def test_update_jwt(self):
5757
headers={
5858
**common.default_headers,
5959
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
60+
"x-descope-project-id": self.dummy_project_id,
6061
},
6162
json={
6263
"jwt": "test",
@@ -77,6 +78,7 @@ def test_update_jwt(self):
7778
headers={
7879
**common.default_headers,
7980
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
81+
"x-descope-project-id": self.dummy_project_id,
8082
},
8183
json={
8284
"jwt": "test",
@@ -126,6 +128,7 @@ def test_impersonate(self):
126128
headers={
127129
**common.default_headers,
128130
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
131+
"x-descope-project-id": self.dummy_project_id,
129132
},
130133
json={
131134
"loginId": "imp2",
@@ -171,6 +174,7 @@ def test_sign_in(self):
171174
headers={
172175
**common.default_headers,
173176
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
177+
"x-descope-project-id": self.dummy_project_id,
174178
},
175179
json={
176180
"loginId": "loginId",
@@ -210,6 +214,7 @@ def test_sign_up(self):
210214
headers={
211215
**common.default_headers,
212216
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
217+
"x-descope-project-id": self.dummy_project_id,
213218
},
214219
json={
215220
"loginId": "loginId",
@@ -259,6 +264,7 @@ def test_sign_up_or_in(self):
259264
headers={
260265
**common.default_headers,
261266
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
267+
"x-descope-project-id": self.dummy_project_id,
262268
},
263269
json={
264270
"loginId": "loginId",
@@ -305,6 +311,7 @@ def test_anonymous(self):
305311
headers={
306312
**common.default_headers,
307313
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
314+
"x-descope-project-id": self.dummy_project_id,
308315
},
309316
json={"customClaims": {"k1": "v1"}, "selectedTenant": "id"},
310317
allow_redirects=False,

0 commit comments

Comments
 (0)