Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/shield/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub trait Subprovider: Send + Sync {

fn name(&self) -> String;

fn icon_url(&self) -> Option<String>;

fn form(&self) -> Option<Form>;
}

Expand All @@ -57,6 +59,7 @@ pub struct SubproviderVisualisation {
pub provider_id: String,
pub subprovider_id: Option<String>,
pub name: String,
pub icon_url: Option<String>,
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions packages/core/shield/src/shield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl<U: User> Shield<U> {
provider_id,
subprovider_id,
name: subprovider.name(),
icon_url: subprovider.icon_url(),
}
})
.collect()
Expand Down
5 changes: 5 additions & 0 deletions packages/providers/shield-oauth/src/subprovider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct OauthSubprovider {
pub(crate) revocation_url: Option<String>,
pub(crate) revocation_url_params: Option<String>,
pub(crate) pkce_code_challenge: OauthProviderPkceCodeChallenge,
pub(crate) icon_url: Option<String>,
}

impl Subprovider for OauthSubprovider {
Expand All @@ -51,6 +52,10 @@ impl Subprovider for OauthSubprovider {
self.name.clone()
}

fn icon_url(&self) -> Option<String> {
self.icon_url.clone()
}

fn form(&self) -> Option<Form> {
None
}
Expand Down
5 changes: 3 additions & 2 deletions packages/providers/shield-oidc/src/builders/google.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::subprovider::{
oidc_subprovider_builder::{SetClientId, SetDiscoveryUrl, SetId, SetName},
oidc_subprovider_builder::{SetClientId, SetDiscoveryUrl, SetIconUrl, SetId, SetName},
OidcSubprovider, OidcSubproviderBuilder,
};

Expand All @@ -9,10 +9,11 @@ impl Google {
pub fn builder(
id: &str,
client_id: &str,
) -> OidcSubproviderBuilder<SetDiscoveryUrl<SetClientId<SetName<SetId>>>> {
) -> OidcSubproviderBuilder<SetDiscoveryUrl<SetClientId<SetIconUrl<SetName<SetId>>>>> {
OidcSubprovider::builder()
.id(id)
.name("Google")
.icon_url("https://authjs.dev/img/providers/google.svg")
.client_id(client_id)
.discovery_url("https://accounts.google.com")
}
Expand Down
5 changes: 3 additions & 2 deletions packages/providers/shield-oidc/src/builders/keycloak.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::subprovider::{
oidc_subprovider_builder::{SetClientId, SetDiscoveryUrl, SetId, SetName},
oidc_subprovider_builder::{SetClientId, SetDiscoveryUrl, SetIconUrl, SetId, SetName},
OidcSubprovider, OidcSubproviderBuilder,
};

Expand All @@ -10,10 +10,11 @@ impl Keycloak {
id: &str,
discovery_url: &str,
client_id: &str,
) -> OidcSubproviderBuilder<SetDiscoveryUrl<SetClientId<SetName<SetId>>>> {
) -> OidcSubproviderBuilder<SetDiscoveryUrl<SetClientId<SetIconUrl<SetName<SetId>>>>> {
OidcSubprovider::builder()
.id(id)
.name("Keycloak")
.icon_url("https://authjs.dev/img/providers/keycloak.svg")
.client_id(client_id)
.discovery_url(discovery_url)
}
Expand Down
5 changes: 5 additions & 0 deletions packages/providers/shield-oidc/src/subprovider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct OidcSubprovider {
pub id: String,
pub name: String,
pub slug: Option<String>,
pub icon_url: Option<String>,
#[builder(default = OidcProviderVisibility::Public)]
pub visibility: OidcProviderVisibility,
pub client_id: String,
Expand Down Expand Up @@ -140,6 +141,10 @@ impl Subprovider for OidcSubprovider {
self.name.clone()
}

fn icon_url(&self) -> Option<String> {
self.icon_url.clone()
}

fn form(&self) -> Option<shield::Form> {
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub struct Model {
#[sea_orm(column_type = "Text", nullable)]
pub revocation_url_params: Option<String>,
pub pkce_code_challenge: OauthProviderPkceCodeChallenge,
#[sea_orm(column_type = "Text", nullable)]
pub icon_url: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 2 additions & 0 deletions packages/storage/shield-sea-orm/src/entities/oidc_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ pub struct Model {
#[sea_orm(column_type = "JsonBinary", nullable)]
pub json_web_key_set: Option<Json>,
pub pkce_code_challenge: OidcProviderPkceCodeChallenge,
#[sea_orm(column_type = "Text", nullable)]
pub icon_url: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod m20241211_095111_create_provider_oauth;
mod m20250118_133257_add_icon_url;

use async_trait::async_trait;
use sea_orm_migration::{MigrationTrait, MigratorTrait};
Expand All @@ -8,8 +9,9 @@ pub struct ProviderOauthMigrator;
#[async_trait]
impl MigratorTrait for ProviderOauthMigrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(
self::m20241211_095111_create_provider_oauth::Migration,
)]
vec![
Box::new(self::m20241211_095111_create_provider_oauth::Migration),
Box::new(self::m20250118_133257_add_icon_url::Migration),
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use async_trait::async_trait;
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(OauthProvider::Table)
.add_column(ColumnDef::new(OauthProvider::IconUrl).text())
.to_owned(),
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(OauthProvider::Table)
.drop_column(OauthProvider::IconUrl)
.to_owned(),
)
.await
}
}

#[derive(DeriveIden)]
enum OauthProvider {
Table,

IconUrl,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod m20241211_184751_create_provider_oidc;
mod m20250118_133731_add_icon_url;

use async_trait::async_trait;
use sea_orm_migration::{MigrationTrait, MigratorTrait};
Expand All @@ -8,8 +9,9 @@ pub struct ProviderOidcMigrator;
#[async_trait]
impl MigratorTrait for ProviderOidcMigrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(
self::m20241211_184751_create_provider_oidc::Migration,
)]
vec![
Box::new(self::m20241211_184751_create_provider_oidc::Migration),
Box::new(self::m20250118_133731_add_icon_url::Migration),
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use async_trait::async_trait;
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(OidcProvider::Table)
.add_column(ColumnDef::new(OidcProvider::IconUrl).text())
.to_owned(),
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(OidcProvider::Table)
.drop_column(OidcProvider::IconUrl)
.to_owned(),
)
.await
}
}

#[derive(DeriveIden)]
enum OidcProvider {
Table,

IconUrl,
}
1 change: 1 addition & 0 deletions packages/storage/shield-sea-orm/src/providers/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl TryFrom<oidc_provider::Model> for OidcSubprovider {
id: value.id.to_string(),
name: value.name,
slug: value.slug,
icon_url: value.icon_url,
visibility: value.visibility.into(),
client_id: value.client_id,
client_secret: value.client_secret,
Expand Down
Loading