Skip to content

Commit 5cfdcfe

Browse files
feat(email): add email method (#332)
1 parent 1e43549 commit 5cfdcfe

35 files changed

Lines changed: 932 additions & 94 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ dioxus-html = "0.7.0-rc.3"
4545
dioxus-server = "0.7.0-rc.3"
4646
futures = "0.3.31"
4747
http = "1.2.0"
48+
jsonwebtoken = "10.3.0"
4849
leptos = "0.8.3"
4950
leptos_actix = "0.8.3"
5051
leptos_axum = "0.8.3"
5152
leptos_meta = "0.8.3"
5253
leptos_router = "0.8.3"
54+
rand = "0.10.0"
5355
regex = "1.12.2"
5456
sea-orm = "1.1.2"
5557
sea-orm-migration = "1.1.2"

examples/axum/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ version.workspace = true
1313
axum.workspace = true
1414
shield.workspace = true
1515
shield-axum = { workspace = true, features = ["utoipa"] }
16-
shield-memory = { workspace = true, features = ["method-oidc"] }
16+
shield-email = { workspace = true, features = ["sender-tracing"] }
17+
shield-memory = { workspace = true, features = ["method-email", "method-oidc"] }
1718
shield-oidc = { workspace = true, features = ["native-tls"] }
1819
time = "0.3.47"
1920
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

examples/axum/src/main.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::sync::Arc;
44
use axum::{Json, middleware::from_fn, routing::get};
55
use shield::{Shield, ShieldOptions};
66
use shield_axum::{AuthRoutes, ShieldLayer, auth_required};
7+
use shield_email::{EmailMethod, EmailOptions, TracingSender};
78
use shield_memory::{MemoryStorage, User};
89
use shield_oidc::{Keycloak, OidcMethod, OidcOptions};
910
use time::Duration;
@@ -34,28 +35,37 @@ async fn main() {
3435
let storage = MemoryStorage::new();
3536
let shield = Shield::new(
3637
storage.clone(),
37-
vec![Arc::new(
38-
OidcMethod::new(storage)
39-
.with_providers([Keycloak::builder(
40-
"keycloak",
41-
"http://localhost:18080/realms/Shield",
42-
"client1",
43-
)
44-
.client_secret("xcpQsaGbRILTljPtX4npjmYMBjKrariJ")
45-
.redirect_url(format!(
46-
"http://localhost:{}/api/auth/oidc/sign-in-callback/keycloak",
47-
addr.port()
48-
))
49-
.build()])
50-
.with_options(
51-
OidcOptions::builder()
52-
.redirect_origins([
53-
Url::parse(&format!("http://localhost:{}", addr.port())).unwrap(),
54-
Url::parse("http://localhost:5173").unwrap(),
55-
])
56-
.build(),
57-
),
58-
)],
38+
vec![
39+
Arc::new(EmailMethod::new(
40+
EmailOptions::builder()
41+
.secret("secret")
42+
.sender(TracingSender)
43+
.build(),
44+
storage.clone(),
45+
)),
46+
Arc::new(
47+
OidcMethod::new(storage)
48+
.with_providers([Keycloak::builder(
49+
"keycloak",
50+
"http://localhost:18080/realms/Shield",
51+
"client1",
52+
)
53+
.client_secret("xcpQsaGbRILTljPtX4npjmYMBjKrariJ")
54+
.redirect_url(format!(
55+
"http://localhost:{}/api/auth/oidc/sign-in-callback/keycloak",
56+
addr.port()
57+
))
58+
.build()])
59+
.with_options(
60+
OidcOptions::builder()
61+
.redirect_origins([
62+
Url::parse(&format!("http://localhost:{}", addr.port())).unwrap(),
63+
Url::parse("http://localhost:5173").unwrap(),
64+
])
65+
.build(),
66+
),
67+
),
68+
],
5969
ShieldOptions::default(),
6070
);
6171
let shield_layer = ShieldLayer::new(shield.clone());

examples/dioxus-axum/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ version.workspace = true
1616
server = [
1717
"dep:axum",
1818
"dep:shield-dioxus-axum",
19+
"dep:shield-email",
1920
"dep:shield-memory",
2021
"dep:shield-oidc",
2122
"dep:tokio",
2223
"dep:tower-sessions",
2324
"dioxus/server",
2425
"shield-dioxus/server",
26+
"shield-memory/method-email",
2527
"shield-memory/method-oidc",
2628
]
2729
web = ["dioxus/web"]
@@ -33,6 +35,9 @@ shield.workspace = true
3335
shield-bootstrap = { workspace = true, features = ["dioxus"] }
3436
shield-dioxus.workspace = true
3537
shield-dioxus-axum = { workspace = true, optional = true }
38+
shield-email = { workspace = true, features = [
39+
"sender-tracing",
40+
], optional = true }
3641
shield-memory = { workspace = true, optional = true }
3742
shield-oidc = { workspace = true, features = ["native-tls"], optional = true }
3843
tokio = { workspace = true, features = [

0 commit comments

Comments
 (0)