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
1,082 changes: 1,055 additions & 27 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ axum = "0.8.1"
bon = "3.3.2"
chrono = "0.4.39"
console_error_panic_hook = "0.1.2"
dioxus = "0.7.0-alpha.1"
futures = "0.3.31"
http = "1.2.0"
leptos = "0.8.0-beta"
Expand All @@ -37,6 +38,8 @@ shield-actix = { path = "./packages/integrations/shield-actix", version = "0.0.4
shield-axum = { path = "./packages/integrations/shield-axum", version = "0.0.4" }
shield-credentials = { path = "./packages/methods/shield-credentials", version = "0.0.4" }
shield-diesel = { path = "./packages/storage/shield-diesel", version = "0.0.4" }
shield-dioxus = { path = "./packages/integrations/shield-dioxus", version = "0.0.4" }
shield-dioxus-axum = { path = "./packages/integrations/shield-dioxus-axum", version = "0.0.4" }
shield-email = { path = "./packages/methods/shield-email", version = "0.0.4" }
shield-leptos = { path = "./packages/integrations/shield-leptos", version = "0.0.4" }
shield-leptos-actix = { path = "./packages/integrations/shield-leptos-actix", version = "0.0.4" }
Expand All @@ -59,3 +62,15 @@ utoipa = { version = "5.3.1", features = ["chrono", "uuid"] }
uuid = "1.11.0"
wasm-bindgen = "0.2.100"
wasm-tracing = "2.0.0"

[profile]

[profile.wasm-dev]
inherits = "dev"
opt-level = 1

[profile.server-dev]
inherits = "dev"

[profile.android-dev]
inherits = "dev"
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ allow = [
"Apache-2.0",
"BSD-3-Clause",
"BSL-1.0",
"CC0-1.0",
"CDLA-Permissive-2.0",
"ISC",
"MIT",
Expand Down
38 changes: 38 additions & 0 deletions examples/dioxus-axum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "shield-examples-diouxs-axum"
description = "Example with Dioxus and Axum."
publish = false

authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true

[features]
default = ["server"]
# TODO: Enabling these triggers multiple RustSec advisories.
# desktop = ["dioxus/desktop"]
# mobile = ["dioxus/mobile"]
server = [
"dep:axum",
"dep:shield-dioxus-axum",
"dep:shield-memory",
"dep:shield-oidc",
"dep:tokio",
"dep:tower-sessions",
"dioxus/server",
"shield-memory/method-oidc",
]
web = ["dioxus/web"]

[dependencies]
axum = { workspace = true, optional = true }
dioxus = { workspace = true, features = ["router", "fullstack"] }
shield.workspace = true
shield-dioxus-axum = { workspace = true, optional = true }
shield-memory = { workspace = true, optional = true }
shield-oidc = { workspace = true, features = ["native-tls"], optional = true }
tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
tower-sessions = { workspace = true, optional = true }
tracing.workspace = true
11 changes: 11 additions & 0 deletions examples/dioxus-axum/Dioxus.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[application]

[web.app]
title = "Shield Dioxus Axum Example"

[web.resource]
style = []
script = []

[web.resource.dev]
script = []
8 changes: 8 additions & 0 deletions examples/dioxus-axum/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
await-holding-invalid-types = [
"generational_box::GenerationalRef",
{ path = "generational_box::GenerationalRef", reason = "Reads should not be held over an await point. This will cause any writes to fail while the await is pending since the read borrow is still active." },
"generational_box::GenerationalRefMut",
{ path = "generational_box::GenerationalRefMut", reason = "Write should not be held over an await point. This will cause any reads or writes to fail while the await is pending since the write borrow is still active." },
"dioxus_signals::Write",
{ path = "dioxus_signals::Write", reason = "Write should not be held over an await point. This will cause any reads or writes to fail while the await is pending since the write borrow is still active." },
]
19 changes: 19 additions & 0 deletions examples/dioxus-axum/src/app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use dioxus::prelude::*;

use crate::home::Home;

#[derive(Debug, Clone, Routable, PartialEq)]
#[rustfmt::skip]
enum Route {
#[route("/")]
Home {},
}

#[component]
pub fn App() -> Element {
rsx! {
main {
Router::<Route> {}
}
}
}
8 changes: 8 additions & 0 deletions examples/dioxus-axum/src/home.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use dioxus::prelude::*;

#[component]
pub fn Home() -> Element {
rsx! {
h1 { "Shield Dioxus Axum Example" }
}
}
72 changes: 72 additions & 0 deletions examples/dioxus-axum/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
mod app;
mod home;

use crate::app::App;

#[cfg(not(feature = "server"))]
fn main() {
dioxus::launch(App);
}

#[cfg(feature = "server")]
#[tokio::main]
async fn main() {
use std::sync::Arc;

use axum::Router;
use dioxus::{
cli_config::fullstack_address_or_localhost,
prelude::{DioxusRouterExt, *},
};
use shield::{Shield, ShieldOptions};
use shield_dioxus_axum::ShieldLayer;
use shield_memory::MemoryStorage;
use shield_oidc::{Keycloak, OidcMethod};
use tokio::net::TcpListener;
use tower_sessions::{Expiry, MemoryStore, SessionManagerLayer, cookie::time::Duration};
use tracing::{Level, info};

// Initialize Dioxus
let addr = fullstack_address_or_localhost();
dioxus::logger::init(Level::DEBUG).unwrap();

// Initialize sessions
let session_store = MemoryStore::default();
let session_layer = SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(Expiry::OnInactivity(Duration::minutes(10)));

// Initialize Shield
let storage = MemoryStorage::new();
let shield = Shield::new(
storage.clone(),
vec![Arc::new(
OidcMethod::new(storage).with_providers([Keycloak::builder(
"keycloak",
"http://localhost:18080/realms/Shield",
"client1",
)
.client_secret("xcpQsaGbRILTljPtX4npjmYMBjKrariJ")
.redirect_url(format!(
"http://localhost:{}/api/auth/sign-in/callback/oidc/keycloak",
addr.port()
))
.build()]),
)],
ShieldOptions::default(),
);
let shield_layer = ShieldLayer::new(shield.clone());

// Initialize router
let router = Router::new()
.serve_dioxus_application(ServeConfig::new().unwrap(), App)
.layer(shield_layer)
.layer(session_layer);

// Start app
info!("listening on http://{}", &addr);
let listener = TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, router.into_make_service())
.await
.unwrap();
}
16 changes: 16 additions & 0 deletions packages/integrations/shield-dioxus-axum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "shield-dioxus-axum"
description = "Dioxus Axum integration for Shield."

authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true

[features]
default = []
utoipa = ["shield-axum/utoipa"]

[dependencies]
shield-axum.workspace = true
1 change: 1 addition & 0 deletions packages/integrations/shield-dioxus-axum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use shield_axum::*;
11 changes: 11 additions & 0 deletions packages/integrations/shield-dioxus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "shield-dioxus"
description = "Dioxus integration for Shield."

authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true

[dependencies]
13 changes: 13 additions & 0 deletions packages/integrations/shield-dioxus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1 align="center">Shield Dioxus</h1>

[Dioxus](https://dioxuslabs.com/) integration for Shield.

## Documentation

See [the Shield book](https://shield.rustforweb.org/) for documentation.

## Rust for Web

The Shield project is part of [Rust for Web](https://github.com/RustForWeb).

[Rust for Web](https://github.com/RustForWeb) creates and ports web libraries for Rust. All projects are free and open source.
1 change: 1 addition & 0 deletions packages/integrations/shield-dioxus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@