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

Commit

Permalink
Add upstream OAuth 2.0 providers name and branding
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Nov 20, 2023
1 parent a5428f1 commit 5126d36
Show file tree
Hide file tree
Showing 21 changed files with 295 additions and 107 deletions.
2 changes: 2 additions & 0 deletions crates/cli/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ async fn sync(root: &super::Options, prune: bool, dry_run: bool) -> anyhow::Resu
provider.id,
UpstreamOAuthProviderParams {
issuer: provider.issuer,
human_name: provider.human_name,
brand_name: provider.brand_name,
scope: provider.scope.parse()?,
token_endpoint_auth_method,
token_endpoint_signing_alg,
Expand Down
16 changes: 16 additions & 0 deletions crates/config/src/sections/upstream_oauth2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ pub struct Provider {
/// The OIDC issuer URL
pub issuer: String,

/// A human-readable name for the provider, that will be shown to users
pub human_name: Option<String>,

/// A brand identifier used to customise the UI, e.g. `apple`, `google`,
/// `github`, etc.
///
/// Values supported by the default template are:
///
/// - `apple`
/// - `google`
/// - `facebook`
/// - `github`
/// - `gitlab`
/// - `twitter`
pub brand_name: Option<String>,

/// The client ID to use when authenticating with the provider
pub client_id: String,

Expand Down
2 changes: 2 additions & 0 deletions crates/data-model/src/upstream_oauth2/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ impl std::fmt::Display for PkceMode {
pub struct UpstreamOAuthProvider {
pub id: Ulid,
pub issuer: String,
pub human_name: Option<String>,
pub brand_name: Option<String>,
pub discovery_mode: DiscoveryMode,
pub pkce_mode: PkceMode,
pub jwks_uri_override: Option<Url>,
Expand Down
2 changes: 2 additions & 0 deletions crates/handlers/src/upstream_oauth2/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ mod tests {
let provider = UpstreamOAuthProvider {
id: Ulid::nil(),
issuer: "https://valid.example.com/".to_owned(),
human_name: Some("Example Ltd.".to_owned()),
brand_name: None,
discovery_mode: UpstreamOAuthProviderDiscoveryMode::Oidc,
pkce_mode: UpstreamOAuthProviderPkceMode::Auto,
jwks_uri_override: None,
Expand Down
2 changes: 2 additions & 0 deletions crates/handlers/src/upstream_oauth2/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ mod tests {
&state.clock,
UpstreamOAuthProviderParams {
issuer: "https://example.com/".to_owned(),
human_name: Some("Example Ltd.".to_owned()),
brand_name: None,
scope: Scope::from_iter([OPENID]),
token_endpoint_auth_method: OAuthClientAuthenticationMethod::None,
token_endpoint_signing_alg: None,
Expand Down
8 changes: 6 additions & 2 deletions crates/handlers/src/views/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ mod test {
&state.clock,
UpstreamOAuthProviderParams {
issuer: "https://first.com/".to_owned(),
human_name: Some("First Ltd.".to_owned()),
brand_name: None,
scope: [OPENID].into_iter().collect(),
token_endpoint_auth_method: OAuthClientAuthenticationMethod::None,
token_endpoint_signing_alg: None,
Expand Down Expand Up @@ -383,6 +385,8 @@ mod test {
&state.clock,
UpstreamOAuthProviderParams {
issuer: "https://second.com/".to_owned(),
human_name: Some("Second Ltd.".to_owned()),
brand_name: None,
scope: [OPENID].into_iter().collect(),
token_endpoint_auth_method: OAuthClientAuthenticationMethod::None,
token_endpoint_signing_alg: None,
Expand All @@ -405,11 +409,11 @@ mod test {
let response = state.request(Request::get("/login").empty()).await;
response.assert_status(StatusCode::OK);
response.assert_header_value(CONTENT_TYPE, "text/html; charset=utf-8");
assert!(response.body().contains(&escape_html("first.com/")));
assert!(response.body().contains(&escape_html("First Ltd.")));
assert!(response
.body()
.contains(&escape_html(&first_provider_login.path_and_query())));
assert!(response.body().contains(&escape_html("second.com/")));
assert!(response.body().contains(&escape_html("Second Ltd.")));
assert!(response
.body()
.contains(&escape_html(&second_provider_login.path_and_query())));
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Loading

0 comments on commit 5126d36

Please sign in to comment.