Skip to content

Commit b59f23e

Browse files
committed
adding dev-v0.25.1 tag to this commit to ensure building
1 parent 85a2b7d commit b59f23e

File tree

2 files changed

+99
-129
lines changed

2 files changed

+99
-129
lines changed

html/supertokens_python/recipe/dashboard/api/multitenancy/get_third_party_config.html

Lines changed: 66 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,21 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
125125

126126
additional_config: Optional[Dict[str, Any]] = None
127127

128+
# filter out providers that is not matching thirdPartyId
128129
providers_from_core = [
129130
provider
130131
for provider in providers_from_core
131132
if provider.third_party_id == third_party_id
132133
]
133134

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:
135137
providers_from_core.append(ProviderConfig(third_party_id=third_party_id))
136138

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+
137143
if third_party_id in [&#34;okta&#34;, &#34;active-directory&#34;, &#34;boxy-saml&#34;, &#34;google-workspaces&#34;]:
138144
if third_party_id == &#34;okta&#34;:
139145
okta_domain = options.request.get_query_param(&#34;oktaDomain&#34;)
@@ -163,28 +169,19 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
163169

164170
if providers_from_core[0].clients is not None:
165171
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=&#34;nonguessable-temporary-client-id&#34;,
177-
additional_config=additional_config,
178-
)
179-
]
172+
existing_client.additional_config = {
173+
**(existing_client.additional_config or {}),
174+
**additional_config
175+
}
180176

177+
# filter out other providers from static
181178
static_providers = [
182179
provider
183180
for provider in static_providers
184181
if provider.config.third_party_id == third_party_id
185182
]
186183

187-
if not static_providers and third_party_id == &#34;apple&#34;:
184+
if len(static_providers) == 0 and third_party_id == &#34;apple&#34;:
188185
static_providers.append(
189186
ProviderInput(
190187
config=ProviderConfig(
@@ -204,27 +201,20 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
204201
&#34;privateKey&#34;: &#34;-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----&#34;,
205202
}
206203

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:
215214
existing_client.additional_config = {
216-
**existing_client.additional_config,
215+
**(existing_client.additional_config or {}),
217216
**additional_config,
218217
}
219-
else:
220-
existing_client.additional_config = additional_config
221-
else:
222-
static_providers[0].config.clients = [
223-
ProviderClientConfig(
224-
client_id=&#34;nonguessable-temporary-client-id&#34;,
225-
additional_config=additional_config,
226-
)
227-
]
228218

229219
merged_providers_from_core_and_static = merge_providers_from_core_and_static(
230220
providers_from_core, static_providers, True
@@ -235,15 +225,14 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
235225

236226
for merged_provider in merged_providers_from_core_and_static:
237227
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:
239229
merged_provider.config.clients = [
240230
ProviderClientConfig(
241231
client_id=&#34;nonguessable-temporary-client-id&#34;,
242-
additional_config=(
243-
additional_config if additional_config is not None else None
244-
),
232+
additional_config=additional_config,
245233
)
246234
]
235+
247236
clients: List[ProviderClientConfig] = []
248237
common_provider_config: CommonProviderConfig = CommonProviderConfig(
249238
third_party_id=third_party_id
@@ -256,7 +245,7 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
256245
if provider.config.third_party_id == third_party_id:
257246
found_correct_config = False
258247

259-
for client in provider.config.clients or []:
248+
for client in (provider.config.clients or []):
260249
try:
261250
provider_instance = await find_and_create_provider_instance(
262251
merged_providers_from_core_and_static,
@@ -327,7 +316,7 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
327316

328317
break
329318

330-
if additional_config and &#34;privateKey&#34; in additional_config:
319+
if additional_config is not None and &#34;privateKey&#34; in additional_config:
331320
additional_config[&#34;privateKey&#34;] = &#34;&#34;
332321

333322
temp_clients = [
@@ -341,18 +330,19 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.api.multitena
341330
for client in clients
342331
if client.client_id != &#34;nonguessable-temporary-client-id&#34;
343332
]
344-
if not final_clients:
333+
if len(final_clients) == 0:
345334
final_clients = [
346335
ProviderClientConfig(
347336
client_id=&#34;&#34;,
348337
client_secret=&#34;&#34;,
349-
additional_config=additional_config,
350338
client_type=temp_clients[0].client_type,
351-
force_pkce=temp_clients[0].force_pkce,
352339
scope=temp_clients[0].scope,
340+
force_pkce=temp_clients[0].force_pkce,
341+
additional_config=additional_config,
353342
)
354343
]
355344

345+
# fill in boxy info from boxy instance
356346
if third_party_id.startswith(&#34;boxy-saml&#34;):
357347
boxy_api_key = options.request.get_query_param(&#34;boxyAPIKey&#34;)
358348
if boxy_api_key and final_clients[0].client_id:
@@ -446,15 +436,21 @@ <h2 class="section-title" id="header-functions">Functions</h2>
446436

447437
additional_config: Optional[Dict[str, Any]] = None
448438

439+
# filter out providers that is not matching thirdPartyId
449440
providers_from_core = [
450441
provider
451442
for provider in providers_from_core
452443
if provider.third_party_id == third_party_id
453444
]
454445

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:
456448
providers_from_core.append(ProviderConfig(third_party_id=third_party_id))
457449

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+
458454
if third_party_id in [&#34;okta&#34;, &#34;active-directory&#34;, &#34;boxy-saml&#34;, &#34;google-workspaces&#34;]:
459455
if third_party_id == &#34;okta&#34;:
460456
okta_domain = options.request.get_query_param(&#34;oktaDomain&#34;)
@@ -484,28 +480,19 @@ <h2 class="section-title" id="header-functions">Functions</h2>
484480

485481
if providers_from_core[0].clients is not None:
486482
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=&#34;nonguessable-temporary-client-id&#34;,
498-
additional_config=additional_config,
499-
)
500-
]
483+
existing_client.additional_config = {
484+
**(existing_client.additional_config or {}),
485+
**additional_config
486+
}
501487

488+
# filter out other providers from static
502489
static_providers = [
503490
provider
504491
for provider in static_providers
505492
if provider.config.third_party_id == third_party_id
506493
]
507494

508-
if not static_providers and third_party_id == &#34;apple&#34;:
495+
if len(static_providers) == 0 and third_party_id == &#34;apple&#34;:
509496
static_providers.append(
510497
ProviderInput(
511498
config=ProviderConfig(
@@ -525,27 +512,20 @@ <h2 class="section-title" id="header-functions">Functions</h2>
525512
&#34;privateKey&#34;: &#34;-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----&#34;,
526513
}
527514

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:
536525
existing_client.additional_config = {
537-
**existing_client.additional_config,
526+
**(existing_client.additional_config or {}),
538527
**additional_config,
539528
}
540-
else:
541-
existing_client.additional_config = additional_config
542-
else:
543-
static_providers[0].config.clients = [
544-
ProviderClientConfig(
545-
client_id=&#34;nonguessable-temporary-client-id&#34;,
546-
additional_config=additional_config,
547-
)
548-
]
549529

550530
merged_providers_from_core_and_static = merge_providers_from_core_and_static(
551531
providers_from_core, static_providers, True
@@ -556,15 +536,14 @@ <h2 class="section-title" id="header-functions">Functions</h2>
556536

557537
for merged_provider in merged_providers_from_core_and_static:
558538
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:
560540
merged_provider.config.clients = [
561541
ProviderClientConfig(
562542
client_id=&#34;nonguessable-temporary-client-id&#34;,
563-
additional_config=(
564-
additional_config if additional_config is not None else None
565-
),
543+
additional_config=additional_config,
566544
)
567545
]
546+
568547
clients: List[ProviderClientConfig] = []
569548
common_provider_config: CommonProviderConfig = CommonProviderConfig(
570549
third_party_id=third_party_id
@@ -577,7 +556,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
577556
if provider.config.third_party_id == third_party_id:
578557
found_correct_config = False
579558

580-
for client in provider.config.clients or []:
559+
for client in (provider.config.clients or []):
581560
try:
582561
provider_instance = await find_and_create_provider_instance(
583562
merged_providers_from_core_and_static,
@@ -648,7 +627,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
648627

649628
break
650629

651-
if additional_config and &#34;privateKey&#34; in additional_config:
630+
if additional_config is not None and &#34;privateKey&#34; in additional_config:
652631
additional_config[&#34;privateKey&#34;] = &#34;&#34;
653632

654633
temp_clients = [
@@ -662,18 +641,19 @@ <h2 class="section-title" id="header-functions">Functions</h2>
662641
for client in clients
663642
if client.client_id != &#34;nonguessable-temporary-client-id&#34;
664643
]
665-
if not final_clients:
644+
if len(final_clients) == 0:
666645
final_clients = [
667646
ProviderClientConfig(
668647
client_id=&#34;&#34;,
669648
client_secret=&#34;&#34;,
670-
additional_config=additional_config,
671649
client_type=temp_clients[0].client_type,
672-
force_pkce=temp_clients[0].force_pkce,
673650
scope=temp_clients[0].scope,
651+
force_pkce=temp_clients[0].force_pkce,
652+
additional_config=additional_config,
674653
)
675654
]
676655

656+
# fill in boxy info from boxy instance
677657
if third_party_id.startswith(&#34;boxy-saml&#34;):
678658
boxy_api_key = options.request.get_query_param(&#34;boxyAPIKey&#34;)
679659
if boxy_api_key and final_clients[0].client_id:

0 commit comments

Comments
 (0)