Skip to content

Commit 32427fd

Browse files
authored
Admin API to list upstream OAuth 2.0 providers (#5043)
2 parents fb8c2a7 + 04758be commit 32427fd

File tree

6 files changed

+891
-0
lines changed

6 files changed

+891
-0
lines changed

crates/handlers/src/admin/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ fn finish(t: TransformOpenApi) -> TransformOpenApi {
9191
),
9292
..Default::default()
9393
})
94+
.tag(Tag {
95+
name: "upstream-oauth-provider".to_owned(),
96+
description: Some("Manage upstream OAuth 2.0 providers".to_owned()),
97+
..Tag::default()
98+
})
9499
.security_scheme("oauth2", oauth_security_scheme(None))
95100
.security_scheme(
96101
"token",

crates/handlers/src/admin/model.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,3 +695,79 @@ impl UserRegistrationToken {
695695
]
696696
}
697697
}
698+
699+
/// An upstream OAuth 2.0 provider
700+
#[derive(Serialize, JsonSchema)]
701+
pub struct UpstreamOAuthProvider {
702+
#[serde(skip)]
703+
id: Ulid,
704+
705+
/// The OIDC issuer of the provider
706+
issuer: Option<String>,
707+
708+
/// A human-readable name for the provider
709+
human_name: Option<String>,
710+
711+
/// A brand identifier, e.g. "apple" or "google"
712+
brand_name: Option<String>,
713+
714+
/// When the provider was created
715+
created_at: DateTime<Utc>,
716+
717+
/// When the provider was disabled. If null, the provider is enabled.
718+
disabled_at: Option<DateTime<Utc>>,
719+
}
720+
721+
impl From<mas_data_model::UpstreamOAuthProvider> for UpstreamOAuthProvider {
722+
fn from(provider: mas_data_model::UpstreamOAuthProvider) -> Self {
723+
Self {
724+
id: provider.id,
725+
issuer: provider.issuer,
726+
human_name: provider.human_name,
727+
brand_name: provider.brand_name,
728+
created_at: provider.created_at,
729+
disabled_at: provider.disabled_at,
730+
}
731+
}
732+
}
733+
734+
impl Resource for UpstreamOAuthProvider {
735+
const KIND: &'static str = "upstream-oauth-provider";
736+
const PATH: &'static str = "/api/admin/v1/upstream-oauth-providers";
737+
738+
fn id(&self) -> Ulid {
739+
self.id
740+
}
741+
}
742+
743+
impl UpstreamOAuthProvider {
744+
/// Samples of upstream OAuth 2.0 providers
745+
pub fn samples() -> [Self; 3] {
746+
[
747+
Self {
748+
id: Ulid::from_bytes([0x01; 16]),
749+
issuer: Some("https://accounts.google.com".to_owned()),
750+
human_name: Some("Google".to_owned()),
751+
brand_name: Some("google".to_owned()),
752+
created_at: DateTime::default(),
753+
disabled_at: None,
754+
},
755+
Self {
756+
id: Ulid::from_bytes([0x02; 16]),
757+
issuer: Some("https://appleid.apple.com".to_owned()),
758+
human_name: Some("Apple ID".to_owned()),
759+
brand_name: Some("apple".to_owned()),
760+
created_at: DateTime::default(),
761+
disabled_at: Some(DateTime::default()),
762+
},
763+
Self {
764+
id: Ulid::from_bytes([0x03; 16]),
765+
issuer: None,
766+
human_name: Some("Custom OAuth Provider".to_owned()),
767+
brand_name: None,
768+
created_at: DateTime::default(),
769+
disabled_at: None,
770+
},
771+
]
772+
}
773+
}

crates/handlers/src/admin/v1/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod oauth2_sessions;
2323
mod policy_data;
2424
mod site_config;
2525
mod upstream_oauth_links;
26+
mod upstream_oauth_providers;
2627
mod user_emails;
2728
mod user_registration_tokens;
2829
mod user_sessions;
@@ -187,4 +188,11 @@ where
187188
self::upstream_oauth_links::delete_doc,
188189
),
189190
)
191+
.api_route(
192+
"/upstream-oauth-providers",
193+
get_with(
194+
self::upstream_oauth_providers::list,
195+
self::upstream_oauth_providers::list_doc,
196+
),
197+
)
190198
}

0 commit comments

Comments
 (0)