Skip to content

Commit a91d30f

Browse files
refactor: rename provider to method and subprovider to provider (#113)
1 parent fde5af3 commit a91d30f

71 files changed

Lines changed: 631 additions & 642 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ sea-orm = "1.1.2"
3232
sea-orm-migration = "1.1.2"
3333
serde = "1.0.215"
3434
serde_json = "1.0.133"
35+
shield = { path = "./packages/core/shield", version = "0.0.4" }
36+
shield-actix = { path = "./packages/integrations/shield-actix", version = "0.0.4" }
37+
shield-axum = { path = "./packages/integrations/shield-axum", version = "0.0.4" }
38+
shield-credentials = { path = "./packages/methods/shield-credentials", version = "0.0.4" }
39+
shield-diesel = { path = "./packages/storage/shield-diesel", version = "0.0.4" }
40+
shield-email = { path = "./packages/methods/shield-email", version = "0.0.4" }
41+
shield-leptos = { path = "./packages/integrations/shield-leptos", version = "0.0.4" }
42+
shield-leptos-actix = { path = "./packages/integrations/shield-leptos-actix", version = "0.0.4" }
43+
shield-leptos-axum = { path = "./packages/integrations/shield-leptos-axum", version = "0.0.4" }
44+
shield-memory = { path = "./packages/storage/shield-memory", version = "0.0.4" }
45+
shield-oauth = { path = "./packages/methods/shield-oauth", version = "0.0.4" }
46+
shield-oidc = { path = "./packages/methods/shield-oidc", version = "0.0.4" }
47+
shield-sea-orm = { path = "./packages/storage/shield-sea-orm", version = "0.0.4" }
48+
shield-sqlx = { path = "./packages/storage/shield-sqlx", version = "0.0.4" }
49+
shield-tower = { path = "./packages/integrations/shield-tower", version = "0.0.4" }
50+
shield-webauthn = { path = "./packages/methods/shield-webauthn", version = "0.0.4" }
3551
tokio = "1.42.0"
3652
tower-layer = "0.3.3"
3753
tower-service = "0.3.3"

examples/leptos-actix/Cargo.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ leptos.workspace = true
2323
leptos_actix = { workspace = true, optional = true }
2424
leptos_meta.workspace = true
2525
leptos_router.workspace = true
26-
shield = { path = "../../packages/core/shield" }
27-
shield-leptos = { path = "../../packages/integrations/shield-leptos" }
28-
shield-leptos-actix = { path = "../../packages/integrations/shield-leptos-actix", optional = true }
29-
shield-memory = { path = "../../packages/storage/shield-memory", optional = true }
30-
shield-oidc = { path = "../../packages/providers/shield-oidc", features = [
31-
"native-tls",
32-
], optional = true }
26+
shield.workspace = true
27+
shield-leptos.workspace = true
28+
shield-leptos-actix = { workspace = true, optional = true }
29+
shield-memory = { workspace = true, optional = true }
30+
shield-oidc = { workspace = true, features = ["native-tls"], optional = true }
3331
tracing.workspace = true
3432
tracing-subscriber.workspace = true
3533
wasm-bindgen.workspace = true
@@ -49,7 +47,7 @@ ssr = [
4947
"leptos/ssr",
5048
"leptos_meta/ssr",
5149
"leptos_router/ssr",
52-
"shield-memory/provider-oidc",
50+
"shield-memory/method-oidc",
5351
]
5452

5553
[package.metadata.leptos]

examples/leptos-actix/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async fn main() -> std::io::Result<()> {
1212
use shield_examples_leptos_actix::app::*;
1313
use shield_leptos_actix::{ShieldMiddleware, provide_actix_integration};
1414
use shield_memory::{MemoryStorage, User};
15-
use shield_oidc::{Keycloak, OidcProvider};
15+
use shield_oidc::{Keycloak, OidcMethod};
1616
use tracing::{info, level_filters::LevelFilter};
1717

1818
// Initialize tracing
@@ -44,7 +44,7 @@ async fn main() -> std::io::Result<()> {
4444
let shield = Shield::new(
4545
shield_storage.clone(),
4646
vec![Arc::new(
47-
OidcProvider::new(shield_storage).with_subproviders([Keycloak::builder(
47+
OidcMethod::new(shield_storage).with_providers([Keycloak::builder(
4848
"keycloak",
4949
"http://localhost:18080/realms/Shield",
5050
"client1",

examples/leptos-axum/Cargo.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ leptos.workspace = true
1919
leptos_axum = { workspace = true, optional = true }
2020
leptos_meta.workspace = true
2121
leptos_router.workspace = true
22-
shield = { path = "../../packages/core/shield" }
23-
shield-leptos = { path = "../../packages/integrations/shield-leptos" }
24-
shield-leptos-axum = { path = "../../packages/integrations/shield-leptos-axum", features = [
22+
shield.workspace = true
23+
shield-leptos.workspace = true
24+
shield-leptos-axum = { workspace = true, features = [
2525
"utoipa",
2626
], optional = true }
27-
shield-memory = { path = "../../packages/storage/shield-memory", optional = true }
28-
shield-oidc = { path = "../../packages/providers/shield-oidc", features = [
29-
"native-tls",
30-
], optional = true }
27+
shield-memory = { workspace = true, optional = true }
28+
shield-oidc = { workspace = true, features = ["native-tls"], optional = true }
3129
time = "0.3.37"
3230
tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
3331
tower-sessions = { workspace = true, optional = true }
@@ -52,7 +50,7 @@ ssr = [
5250
"leptos/ssr",
5351
"leptos_meta/ssr",
5452
"leptos_router/ssr",
55-
"shield-memory/provider-oidc",
53+
"shield-memory/method-oidc",
5654
]
5755

5856
[package.metadata.leptos]

examples/leptos-axum/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async fn main() {
1010
use shield_examples_leptos_axum::app::*;
1111
use shield_leptos_axum::{AuthRoutes, ShieldLayer, auth_required, provide_axum_integration};
1212
use shield_memory::{MemoryStorage, User};
13-
use shield_oidc::{Keycloak, OidcProvider};
13+
use shield_oidc::{Keycloak, OidcMethod};
1414
use time::Duration;
1515
use tokio::net::TcpListener;
1616
use tower_sessions::{Expiry, MemoryStore, SessionManagerLayer};
@@ -40,7 +40,7 @@ async fn main() {
4040
let shield = Shield::new(
4141
storage.clone(),
4242
vec![Arc::new(
43-
OidcProvider::new(storage).with_subproviders([Keycloak::builder(
43+
OidcMethod::new(storage).with_providers([Keycloak::builder(
4444
"keycloak",
4545
"http://localhost:18080/realms/Shield",
4646
"client1",

examples/sea-orm/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,5 @@ sea-orm-migration = { workspace = true, features = [
2323
"sqlx-postgres",
2424
"sqlx-sqlite",
2525
] }
26-
shield-sea-orm = { path = "../../packages/storage/shield-sea-orm", features = [
27-
"all-providers",
28-
"utoipa",
29-
] }
26+
shield-sea-orm = { workspace = true, features = ["all-methods", "utoipa"] }
3027
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

packages/core/shield/src/error.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
use thiserror::Error;
22

3+
#[derive(Debug, Error)]
4+
pub enum MethodError {
5+
#[error("method `{0}` not found")]
6+
MethodNotFound(String),
7+
}
8+
39
#[derive(Debug, Error)]
410
pub enum ProviderError {
11+
#[error("provider is missing")]
12+
ProviderMissing,
513
#[error("provider `{0}` not found")]
614
ProviderNotFound(String),
7-
#[error("subprovider is missing")]
8-
SubproviderMissing,
9-
#[error("subprovider `{0}` not found")]
10-
SubproviderNotFound(String),
1115
}
1216

1317
#[derive(Debug, Error)]
@@ -45,6 +49,8 @@ pub enum SessionError {
4549
#[derive(Debug, Error)]
4650

4751
pub enum ShieldError {
52+
#[error(transparent)]
53+
Method(#[from] MethodError),
4854
#[error(transparent)]
4955
Provider(#[from] ProviderError),
5056
#[error(transparent)]

packages/core/shield/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod error;
22
mod form;
3+
mod method;
34
mod options;
45
mod provider;
56
mod request;
@@ -12,6 +13,7 @@ mod user;
1213

1314
pub use error::*;
1415
pub use form::*;
16+
pub use method::*;
1517
pub use options::*;
1618
pub use provider::*;
1719
pub use request::*;

packages/core/shield/src/method.rs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
use async_trait::async_trait;
2+
3+
use crate::{
4+
error::ShieldError,
5+
options::ShieldOptions,
6+
provider::Provider,
7+
request::{SignInCallbackRequest, SignInRequest, SignOutRequest},
8+
response::Response,
9+
session::Session,
10+
};
11+
12+
#[async_trait]
13+
pub trait Method: Send + Sync {
14+
fn id(&self) -> String;
15+
16+
async fn providers(&self) -> Result<Vec<Box<dyn Provider>>, ShieldError>;
17+
18+
async fn provider_by_id(
19+
&self,
20+
provider_id: &str,
21+
) -> Result<Option<Box<dyn Provider>>, ShieldError>;
22+
23+
async fn sign_in(
24+
&self,
25+
request: SignInRequest,
26+
session: Session,
27+
options: &ShieldOptions,
28+
) -> Result<Response, ShieldError>;
29+
30+
async fn sign_in_callback(
31+
&self,
32+
request: SignInCallbackRequest,
33+
session: Session,
34+
options: &ShieldOptions,
35+
) -> Result<Response, ShieldError>;
36+
37+
async fn sign_out(
38+
&self,
39+
request: SignOutRequest,
40+
session: Session,
41+
options: &ShieldOptions,
42+
) -> Result<Response, ShieldError>;
43+
}
44+
45+
#[cfg(test)]
46+
pub(crate) mod tests {
47+
use async_trait::async_trait;
48+
49+
use crate::{
50+
ShieldOptions,
51+
error::ShieldError,
52+
provider::Provider,
53+
request::{SignInCallbackRequest, SignInRequest, SignOutRequest},
54+
response::Response,
55+
session::Session,
56+
};
57+
58+
use super::Method;
59+
60+
pub const TEST_METHOD_ID: &str = "test";
61+
62+
#[derive(Default)]
63+
pub struct TestMethod {
64+
id: Option<&'static str>,
65+
}
66+
67+
impl TestMethod {
68+
pub fn with_id(mut self, id: &'static str) -> Self {
69+
self.id = Some(id);
70+
self
71+
}
72+
}
73+
74+
#[async_trait]
75+
impl Method for TestMethod {
76+
fn id(&self) -> String {
77+
self.id.unwrap_or(TEST_METHOD_ID).to_owned()
78+
}
79+
80+
async fn providers(&self) -> Result<Vec<Box<dyn Provider>>, ShieldError> {
81+
Ok(vec![])
82+
}
83+
84+
async fn provider_by_id(
85+
&self,
86+
_provider_id: &str,
87+
) -> Result<Option<Box<dyn Provider>>, ShieldError> {
88+
Ok(None)
89+
}
90+
91+
async fn sign_in(
92+
&self,
93+
_request: SignInRequest,
94+
_session: Session,
95+
_options: &ShieldOptions,
96+
) -> Result<Response, ShieldError> {
97+
todo!("redirect back?")
98+
}
99+
100+
async fn sign_in_callback(
101+
&self,
102+
_request: SignInCallbackRequest,
103+
_session: Session,
104+
_options: &ShieldOptions,
105+
) -> Result<Response, ShieldError> {
106+
todo!("redirect back?")
107+
}
108+
109+
async fn sign_out(
110+
&self,
111+
_request: SignOutRequest,
112+
_session: Session,
113+
_options: &ShieldOptions,
114+
) -> Result<Response, ShieldError> {
115+
todo!("redirect back?")
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)