@@ -125,15 +125,21 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
125
125
126
126
additional_config: Optional[Dict[str, Any]] = None
127
127
128
+ # filter out providers that is not matching thirdPartyId
128
129
providers_from_core = [
129
130
provider
130
131
for provider in providers_from_core
131
132
if provider.third_party_id == third_party_id
132
133
]
133
134
134
- if not providers_from_core:
135
+ # if none left, add one to this list so that it takes priority while merging
136
+ if len(providers_from_core) == 0:
135
137
providers_from_core.append(ProviderConfig(third_party_id=third_party_id))
136
138
139
+ # At this point, providersFromCore.length === 1
140
+
141
+ # query param may be passed if we are creating a new third party config, check and update accordingly
142
+
137
143
if third_party_id in ["okta", "active-directory", "boxy-saml", "google-workspaces"]:
138
144
if third_party_id == "okta":
139
145
okta_domain = options.request.get_query_param("oktaDomain")
@@ -163,28 +169,19 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
163
169
164
170
if providers_from_core[0].clients is not None:
165
171
for existing_client in providers_from_core[0].clients:
166
- if existing_client.additional_config is not None:
167
- existing_client.additional_config = {
168
- **existing_client.additional_config,
169
- **additional_config,
170
- }
171
- else:
172
- existing_client.additional_config = additional_config
173
- else:
174
- providers_from_core[0].clients = [
175
- ProviderClientConfig(
176
- client_id="nonguessable-temporary-client-id",
177
- additional_config=additional_config,
178
- )
179
- ]
172
+ existing_client.additional_config = {
173
+ **(existing_client.additional_config or {}),
174
+ **additional_config
175
+ }
180
176
177
+ # filter out other providers from static
181
178
static_providers = [
182
179
provider
183
180
for provider in static_providers
184
181
if provider.config.third_party_id == third_party_id
185
182
]
186
183
187
- if not static_providers and third_party_id == "apple":
184
+ if len( static_providers) == 0 and third_party_id == "apple":
188
185
static_providers.append(
189
186
ProviderInput(
190
187
config=ProviderConfig(
@@ -204,27 +201,20 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
204
201
"privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----",
205
202
}
206
203
207
- if len(static_providers) == 1 and additional_config is not None:
208
- static_providers[0].config.oidc_discovery_endpoint = None
209
- static_providers[0].config.authorization_endpoint = None
210
- static_providers[0].config.token_endpoint = None
211
- static_providers[0].config.user_info_endpoint = None
212
- if static_providers[0].config.clients is not None:
213
- for existing_client in static_providers[0].config.clients:
214
- if existing_client.additional_config is not None:
204
+ if len(static_providers) == 1:
205
+ # modify additional config if query param is passed
206
+ if additional_config is not None:
207
+ # we set these to undefined so that these can be computed using the query param that was provided
208
+ static_providers[0].config.oidc_discovery_endpoint = None
209
+ static_providers[0].config.authorization_endpoint = None
210
+ static_providers[0].config.token_endpoint = None
211
+ static_providers[0].config.user_info_endpoint = None
212
+ if static_providers[0].config.clients is not None:
213
+ for existing_client in static_providers[0].config.clients:
215
214
existing_client.additional_config = {
216
- **existing_client.additional_config,
215
+ **( existing_client.additional_config or {}) ,
217
216
**additional_config,
218
217
}
219
- else:
220
- existing_client.additional_config = additional_config
221
- else:
222
- static_providers[0].config.clients = [
223
- ProviderClientConfig(
224
- client_id="nonguessable-temporary-client-id",
225
- additional_config=additional_config,
226
- )
227
- ]
228
218
229
219
merged_providers_from_core_and_static = merge_providers_from_core_and_static(
230
220
providers_from_core, static_providers, True
@@ -235,15 +225,14 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
235
225
236
226
for merged_provider in merged_providers_from_core_and_static:
237
227
if merged_provider.config.third_party_id == third_party_id:
238
- if not merged_provider.config.clients:
228
+ if merged_provider.config.clients is None or len( merged_provider.config.clients) == 0 :
239
229
merged_provider.config.clients = [
240
230
ProviderClientConfig(
241
231
client_id="nonguessable-temporary-client-id",
242
- additional_config=(
243
- additional_config if additional_config is not None else None
244
- ),
232
+ additional_config=additional_config,
245
233
)
246
234
]
235
+
247
236
clients: List[ProviderClientConfig] = []
248
237
common_provider_config: CommonProviderConfig = CommonProviderConfig(
249
238
third_party_id=third_party_id
@@ -256,7 +245,7 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
256
245
if provider.config.third_party_id == third_party_id:
257
246
found_correct_config = False
258
247
259
- for client in provider.config.clients or []:
248
+ for client in ( provider.config.clients or []) :
260
249
try:
261
250
provider_instance = await find_and_create_provider_instance(
262
251
merged_providers_from_core_and_static,
@@ -327,7 +316,7 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
327
316
328
317
break
329
318
330
- if additional_config and "privateKey" in additional_config:
319
+ if additional_config is not None and "privateKey" in additional_config:
331
320
additional_config["privateKey"] = ""
332
321
333
322
temp_clients = [
@@ -341,18 +330,19 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
341
330
for client in clients
342
331
if client.client_id != "nonguessable-temporary-client-id"
343
332
]
344
- if not final_clients:
333
+ if len( final_clients) == 0 :
345
334
final_clients = [
346
335
ProviderClientConfig(
347
336
client_id="",
348
337
client_secret="",
349
- additional_config=additional_config,
350
338
client_type=temp_clients[0].client_type,
351
- force_pkce=temp_clients[0].force_pkce,
352
339
scope=temp_clients[0].scope,
340
+ force_pkce=temp_clients[0].force_pkce,
341
+ additional_config=additional_config,
353
342
)
354
343
]
355
344
345
+ # fill in boxy info from boxy instance
356
346
if third_party_id.startswith("boxy-saml"):
357
347
boxy_api_key = options.request.get_query_param("boxyAPIKey")
358
348
if boxy_api_key and final_clients[0].client_id:
@@ -446,15 +436,21 @@ <h2 class="section-title" id="header-functions">Functions</h2>
446
436
447
437
additional_config: Optional[Dict[str, Any]] = None
448
438
439
+ # filter out providers that is not matching thirdPartyId
449
440
providers_from_core = [
450
441
provider
451
442
for provider in providers_from_core
452
443
if provider.third_party_id == third_party_id
453
444
]
454
445
455
- if not providers_from_core:
446
+ # if none left, add one to this list so that it takes priority while merging
447
+ if len(providers_from_core) == 0:
456
448
providers_from_core.append(ProviderConfig(third_party_id=third_party_id))
457
449
450
+ # At this point, providersFromCore.length === 1
451
+
452
+ # query param may be passed if we are creating a new third party config, check and update accordingly
453
+
458
454
if third_party_id in ["okta", "active-directory", "boxy-saml", "google-workspaces"]:
459
455
if third_party_id == "okta":
460
456
okta_domain = options.request.get_query_param("oktaDomain")
@@ -484,28 +480,19 @@ <h2 class="section-title" id="header-functions">Functions</h2>
484
480
485
481
if providers_from_core[0].clients is not None:
486
482
for existing_client in providers_from_core[0].clients:
487
- if existing_client.additional_config is not None:
488
- existing_client.additional_config = {
489
- **existing_client.additional_config,
490
- **additional_config,
491
- }
492
- else:
493
- existing_client.additional_config = additional_config
494
- else:
495
- providers_from_core[0].clients = [
496
- ProviderClientConfig(
497
- client_id="nonguessable-temporary-client-id",
498
- additional_config=additional_config,
499
- )
500
- ]
483
+ existing_client.additional_config = {
484
+ **(existing_client.additional_config or {}),
485
+ **additional_config
486
+ }
501
487
488
+ # filter out other providers from static
502
489
static_providers = [
503
490
provider
504
491
for provider in static_providers
505
492
if provider.config.third_party_id == third_party_id
506
493
]
507
494
508
- if not static_providers and third_party_id == "apple":
495
+ if len( static_providers) == 0 and third_party_id == "apple":
509
496
static_providers.append(
510
497
ProviderInput(
511
498
config=ProviderConfig(
@@ -525,27 +512,20 @@ <h2 class="section-title" id="header-functions">Functions</h2>
525
512
"privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----",
526
513
}
527
514
528
- if len(static_providers) == 1 and additional_config is not None:
529
- static_providers[0].config.oidc_discovery_endpoint = None
530
- static_providers[0].config.authorization_endpoint = None
531
- static_providers[0].config.token_endpoint = None
532
- static_providers[0].config.user_info_endpoint = None
533
- if static_providers[0].config.clients is not None:
534
- for existing_client in static_providers[0].config.clients:
535
- if existing_client.additional_config is not None:
515
+ if len(static_providers) == 1:
516
+ # modify additional config if query param is passed
517
+ if additional_config is not None:
518
+ # we set these to undefined so that these can be computed using the query param that was provided
519
+ static_providers[0].config.oidc_discovery_endpoint = None
520
+ static_providers[0].config.authorization_endpoint = None
521
+ static_providers[0].config.token_endpoint = None
522
+ static_providers[0].config.user_info_endpoint = None
523
+ if static_providers[0].config.clients is not None:
524
+ for existing_client in static_providers[0].config.clients:
536
525
existing_client.additional_config = {
537
- **existing_client.additional_config,
526
+ **( existing_client.additional_config or {}) ,
538
527
**additional_config,
539
528
}
540
- else:
541
- existing_client.additional_config = additional_config
542
- else:
543
- static_providers[0].config.clients = [
544
- ProviderClientConfig(
545
- client_id="nonguessable-temporary-client-id",
546
- additional_config=additional_config,
547
- )
548
- ]
549
529
550
530
merged_providers_from_core_and_static = merge_providers_from_core_and_static(
551
531
providers_from_core, static_providers, True
@@ -556,15 +536,14 @@ <h2 class="section-title" id="header-functions">Functions</h2>
556
536
557
537
for merged_provider in merged_providers_from_core_and_static:
558
538
if merged_provider.config.third_party_id == third_party_id:
559
- if not merged_provider.config.clients:
539
+ if merged_provider.config.clients is None or len( merged_provider.config.clients) == 0 :
560
540
merged_provider.config.clients = [
561
541
ProviderClientConfig(
562
542
client_id="nonguessable-temporary-client-id",
563
- additional_config=(
564
- additional_config if additional_config is not None else None
565
- ),
543
+ additional_config=additional_config,
566
544
)
567
545
]
546
+
568
547
clients: List[ProviderClientConfig] = []
569
548
common_provider_config: CommonProviderConfig = CommonProviderConfig(
570
549
third_party_id=third_party_id
@@ -577,7 +556,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
577
556
if provider.config.third_party_id == third_party_id:
578
557
found_correct_config = False
579
558
580
- for client in provider.config.clients or []:
559
+ for client in ( provider.config.clients or []) :
581
560
try:
582
561
provider_instance = await find_and_create_provider_instance(
583
562
merged_providers_from_core_and_static,
@@ -648,7 +627,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
648
627
649
628
break
650
629
651
- if additional_config and "privateKey" in additional_config:
630
+ if additional_config is not None and "privateKey" in additional_config:
652
631
additional_config["privateKey"] = ""
653
632
654
633
temp_clients = [
@@ -662,18 +641,19 @@ <h2 class="section-title" id="header-functions">Functions</h2>
662
641
for client in clients
663
642
if client.client_id != "nonguessable-temporary-client-id"
664
643
]
665
- if not final_clients:
644
+ if len( final_clients) == 0 :
666
645
final_clients = [
667
646
ProviderClientConfig(
668
647
client_id="",
669
648
client_secret="",
670
- additional_config=additional_config,
671
649
client_type=temp_clients[0].client_type,
672
- force_pkce=temp_clients[0].force_pkce,
673
650
scope=temp_clients[0].scope,
651
+ force_pkce=temp_clients[0].force_pkce,
652
+ additional_config=additional_config,
674
653
)
675
654
]
676
655
656
+ # fill in boxy info from boxy instance
677
657
if third_party_id.startswith("boxy-saml"):
678
658
boxy_api_key = options.request.get_query_param("boxyAPIKey")
679
659
if boxy_api_key and final_clients[0].client_id:
0 commit comments