Skip to content

Commit 2ae1523

Browse files
authored
Order the OAuth providers in the UI by their order in the config file (#4199)
2 parents d1a3ef9 + 36a9131 commit 2ae1523

12 files changed

+77
-48
lines changed

Diff for: crates/cli/src/sync.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,14 @@ pub async fn config_sync(
165165
}
166166
}
167167

168-
for provider in upstream_oauth2_config.providers {
168+
for (index, provider) in upstream_oauth2_config.providers.into_iter().enumerate() {
169169
if !provider.enabled {
170170
continue;
171171
}
172172

173+
// Use the position in the config of the provider as position in the UI
174+
let ui_order = index.try_into().unwrap_or(i32::MAX);
175+
173176
let _span = info_span!("provider", %provider.id).entered();
174177
if existing_enabled_ids.contains(&provider.id) {
175178
info!("Updating provider");
@@ -293,6 +296,7 @@ pub async fn config_sync(
293296
.additional_authorization_parameters
294297
.into_iter()
295298
.collect(),
299+
ui_order,
296300
},
297301
)
298302
.await?;

Diff for: crates/handlers/src/admin/v1/upstream_oauth_links/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ mod test_utils {
4343
userinfo_endpoint_override: None,
4444
jwks_uri_override: None,
4545
additional_authorization_parameters: Vec::new(),
46+
ui_order: 0,
4647
}
4748
}
4849
}

Diff for: crates/handlers/src/upstream_oauth2/link.rs

+1
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ mod tests {
949949
pkce_mode: mas_data_model::UpstreamOAuthProviderPkceMode::Auto,
950950
response_mode: None,
951951
additional_authorization_parameters: Vec::new(),
952+
ui_order: 0,
952953
},
953954
)
954955
.await

Diff for: crates/handlers/src/views/login.rs

+2
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ mod test {
436436
pkce_mode: mas_data_model::UpstreamOAuthProviderPkceMode::Auto,
437437
response_mode: None,
438438
additional_authorization_parameters: Vec::new(),
439+
ui_order: 0,
439440
},
440441
)
441442
.await
@@ -476,6 +477,7 @@ mod test {
476477
pkce_mode: mas_data_model::UpstreamOAuthProviderPkceMode::Auto,
477478
response_mode: None,
478479
additional_authorization_parameters: Vec::new(),
480+
ui_order: 1,
479481
},
480482
)
481483
.await

Diff for: crates/storage-pg/.sqlx/query-72de26d5e3c56f4b0658685a95b45b647bb6637e55b662a5a548aa3308c62a8a.json

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: crates/storage-pg/.sqlx/query-99f2a0b53e08d23408dc2837d32d734c8a0e706662e72f3b2585b0c38f42c063.json

-43
This file was deleted.

Diff for: crates/storage-pg/.sqlx/query-27d6f228a9a608b5d03d30cb4074be94dc893df9107e982583aa954b5067dfd1.json renamed to crates/storage-pg/.sqlx/query-c1e55ffd09181c0d8ddd0df2843690aeae4a20329045ab23639181a0d0903178.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Copyright 2025 New Vector Ltd.
2+
--
3+
-- SPDX-License-Identifier: AGPL-3.0-only
4+
-- Please see LICENSE in the repository root for full details.
5+
6+
-- Adds a column to track the 'UI order' of the upstream OAuth2 providers, so
7+
-- that they can be consistently displayed in the UI
8+
ALTER TABLE upstream_oauth_providers
9+
ADD COLUMN ui_order INTEGER NOT NULL DEFAULT 0;

Diff for: crates/storage-pg/src/upstream_oauth2/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ mod tests {
7676
pkce_mode: mas_data_model::UpstreamOAuthProviderPkceMode::Auto,
7777
response_mode: None,
7878
additional_authorization_parameters: Vec::new(),
79+
ui_order: 0,
7980
},
8081
)
8182
.await
@@ -322,6 +323,7 @@ mod tests {
322323
pkce_mode: mas_data_model::UpstreamOAuthProviderPkceMode::Auto,
323324
response_mode: None,
324325
additional_authorization_parameters: Vec::new(),
326+
ui_order: 0,
325327
},
326328
)
327329
.await

Diff for: crates/storage-pg/src/upstream_oauth2/provider.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,11 @@ impl UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'_> {
517517
pkce_mode,
518518
response_mode,
519519
additional_parameters,
520+
ui_order,
520521
created_at
521522
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11,
522-
$12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)
523+
$12, $13, $14, $15, $16, $17, $18, $19, $20,
524+
$21, $22, $23)
523525
ON CONFLICT (upstream_oauth_provider_id)
524526
DO UPDATE
525527
SET
@@ -543,7 +545,8 @@ impl UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'_> {
543545
discovery_mode = EXCLUDED.discovery_mode,
544546
pkce_mode = EXCLUDED.pkce_mode,
545547
response_mode = EXCLUDED.response_mode,
546-
additional_parameters = EXCLUDED.additional_parameters
548+
additional_parameters = EXCLUDED.additional_parameters,
549+
ui_order = EXCLUDED.ui_order
547550
RETURNING created_at
548551
"#,
549552
Uuid::from(id),
@@ -582,6 +585,7 @@ impl UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'_> {
582585
params.pkce_mode.as_str(),
583586
params.response_mode.as_ref().map(ToString::to_string),
584587
Json(&params.additional_authorization_parameters) as _,
588+
params.ui_order,
585589
created_at,
586590
)
587591
.traced()
@@ -917,6 +921,7 @@ impl UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'_> {
917921
additional_parameters as "additional_parameters: Json<Vec<(String, String)>>"
918922
FROM upstream_oauth_providers
919923
WHERE disabled_at IS NULL
924+
ORDER BY ui_order ASC, upstream_oauth_provider_id ASC
920925
"#,
921926
)
922927
.traced()

Diff for: crates/storage/src/upstream_oauth2/provider.rs

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ pub struct UpstreamOAuthProviderParams {
9595

9696
/// Additional parameters to include in the authorization request
9797
pub additional_authorization_parameters: Vec<(String, String)>,
98+
99+
/// The position of the provider in the UI
100+
pub ui_order: i32,
98101
}
99102

100103
/// Filter parameters for listing upstream OAuth 2.0 providers

Diff for: crates/syn2mas/src/mas_writer/snapshots/syn2mas__mas_writer__test__write_user_with_upstream_provider_link.snap

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ upstream_oauth_providers:
3030
token_endpoint_auth_method: client_secret_basic
3131
token_endpoint_override: ~
3232
token_endpoint_signing_alg: ~
33+
ui_order: "0"
3334
upstream_oauth_provider_id: 00000000-0000-0000-0000-000000000004
3435
userinfo_endpoint_override: ~
3536
userinfo_signed_response_alg: ~

0 commit comments

Comments
 (0)