Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 5126d36

Browse files
committed
Add upstream OAuth 2.0 providers name and branding
1 parent a5428f1 commit 5126d36

21 files changed

+295
-107
lines changed

crates/cli/src/commands/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ async fn sync(root: &super::Options, prune: bool, dry_run: bool) -> anyhow::Resu
267267
provider.id,
268268
UpstreamOAuthProviderParams {
269269
issuer: provider.issuer,
270+
human_name: provider.human_name,
271+
brand_name: provider.brand_name,
270272
scope: provider.scope.parse()?,
271273
token_endpoint_auth_method,
272274
token_endpoint_signing_alg,

crates/config/src/sections/upstream_oauth2.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,22 @@ pub struct Provider {
245245
/// The OIDC issuer URL
246246
pub issuer: String,
247247

248+
/// A human-readable name for the provider, that will be shown to users
249+
pub human_name: Option<String>,
250+
251+
/// A brand identifier used to customise the UI, e.g. `apple`, `google`,
252+
/// `github`, etc.
253+
///
254+
/// Values supported by the default template are:
255+
///
256+
/// - `apple`
257+
/// - `google`
258+
/// - `facebook`
259+
/// - `github`
260+
/// - `gitlab`
261+
/// - `twitter`
262+
pub brand_name: Option<String>,
263+
248264
/// The client ID to use when authenticating with the provider
249265
pub client_id: String,
250266

crates/data-model/src/upstream_oauth2/provider.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ impl std::fmt::Display for PkceMode {
128128
pub struct UpstreamOAuthProvider {
129129
pub id: Ulid,
130130
pub issuer: String,
131+
pub human_name: Option<String>,
132+
pub brand_name: Option<String>,
131133
pub discovery_mode: DiscoveryMode,
132134
pub pkce_mode: PkceMode,
133135
pub jwks_uri_override: Option<Url>,

crates/handlers/src/upstream_oauth2/cache.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ mod tests {
491491
let provider = UpstreamOAuthProvider {
492492
id: Ulid::nil(),
493493
issuer: "https://valid.example.com/".to_owned(),
494+
human_name: Some("Example Ltd.".to_owned()),
495+
brand_name: None,
494496
discovery_mode: UpstreamOAuthProviderDiscoveryMode::Oidc,
495497
pkce_mode: UpstreamOAuthProviderPkceMode::Auto,
496498
jwks_uri_override: None,

crates/handlers/src/upstream_oauth2/link.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,8 @@ mod tests {
861861
&state.clock,
862862
UpstreamOAuthProviderParams {
863863
issuer: "https://example.com/".to_owned(),
864+
human_name: Some("Example Ltd.".to_owned()),
865+
brand_name: None,
864866
scope: Scope::from_iter([OPENID]),
865867
token_endpoint_auth_method: OAuthClientAuthenticationMethod::None,
866868
token_endpoint_signing_alg: None,

crates/handlers/src/views/login.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ mod test {
351351
&state.clock,
352352
UpstreamOAuthProviderParams {
353353
issuer: "https://first.com/".to_owned(),
354+
human_name: Some("First Ltd.".to_owned()),
355+
brand_name: None,
354356
scope: [OPENID].into_iter().collect(),
355357
token_endpoint_auth_method: OAuthClientAuthenticationMethod::None,
356358
token_endpoint_signing_alg: None,
@@ -383,6 +385,8 @@ mod test {
383385
&state.clock,
384386
UpstreamOAuthProviderParams {
385387
issuer: "https://second.com/".to_owned(),
388+
human_name: Some("Second Ltd.".to_owned()),
389+
brand_name: None,
386390
scope: [OPENID].into_iter().collect(),
387391
token_endpoint_auth_method: OAuthClientAuthenticationMethod::None,
388392
token_endpoint_signing_alg: None,
@@ -405,11 +409,11 @@ mod test {
405409
let response = state.request(Request::get("/login").empty()).await;
406410
response.assert_status(StatusCode::OK);
407411
response.assert_header_value(CONTENT_TYPE, "text/html; charset=utf-8");
408-
assert!(response.body().contains(&escape_html("first.com/")));
412+
assert!(response.body().contains(&escape_html("First Ltd.")));
409413
assert!(response
410414
.body()
411415
.contains(&escape_html(&first_provider_login.path_and_query())));
412-
assert!(response.body().contains(&escape_html("second.com/")));
416+
assert!(response.body().contains(&escape_html("Second Ltd.")));
413417
assert!(response
414418
.body()
415419
.contains(&escape_html(&second_provider_login.path_and_query())));

crates/storage-pg/.sqlx/query-1f131aa966a4358d83e7247d3e30451f8bcf5df20faf46a4a4c0d4a36d1ff173.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-311957a0b745660aa2a21b1bd211376739318efa1e84670e04189e1257d4a8ed.json

Lines changed: 0 additions & 27 deletions
This file was deleted.

crates/storage-pg/.sqlx/query-4668abf6520ecca2fa71a26b02d206600624bbba57985d4a7fba2763478cd065.json

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)