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
2 changes: 1 addition & 1 deletion examples/axum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn main() {
)
.client_secret("xcpQsaGbRILTljPtX4npjmYMBjKrariJ")
.redirect_url(format!(
"http://localhost:{}/api/auth/sign-in/callback/oidc/keycloak",
"http://localhost:{}/api/auth/oidc/sign-in-callback/keycloak",
addr.port()
))
.build()]),
Expand Down
8 changes: 5 additions & 3 deletions examples/dioxus-axum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ async fn main() {
use tracing::{Level, info};

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

// Initialize sessions
let session_store = MemoryStore::default();
Expand All @@ -53,8 +53,10 @@ async fn main() {
)
.client_secret("xcpQsaGbRILTljPtX4npjmYMBjKrariJ")
.redirect_url(format!(
"http://localhost:{}/api/auth/sign-in/callback/oidc/keycloak",
addr.port()
"http://localhost:{}/api/auth/oidc/sign-in-callback/keycloak",
dioxus::cli_config::devserver_raw_addr()
.map(|addr| addr.port())
.unwrap_or_else(|| addr.port())
))
.build()]),
)],
Expand Down
2 changes: 2 additions & 0 deletions examples/leptos-actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ bin-default-features = false
lib-features = ["hydrate"]
lib-default-features = false

site-addr = "127.0.0.1:8080"

[lib]
crate-type = ["cdylib", "rlib"]

Expand Down
2 changes: 2 additions & 0 deletions examples/leptos-axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ bin-default-features = false
lib-features = ["hydrate"]
lib-default-features = false

site-addr = "127.0.0.1:8080"

[lib]
crate-type = ["cdylib", "rlib"]

Expand Down
2 changes: 1 addition & 1 deletion examples/leptos-axum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn main() {
)
.client_secret("xcpQsaGbRILTljPtX4npjmYMBjKrariJ")
.redirect_url(format!(
"http://localhost:{}/api/auth/sign-in/callback/oidc/keycloak",
"http://localhost:{}/api/auth/oidc/sign-in-callback/keycloak",
addr.port()
))
.build()]),
Expand Down
6 changes: 3 additions & 3 deletions keycloak/Shield-realm.json
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,14 @@
"description": "",
"rootUrl": "",
"adminUrl": "",
"baseUrl": "http://localhost:3000",
"baseUrl": "http://localhost:8080",
"surrogateAuthRequired": false,
"enabled": true,
"alwaysDisplayInConsole": false,
"clientAuthenticatorType": "client-secret",
"secret": "xcpQsaGbRILTljPtX4npjmYMBjKrariJ",
"redirectUris": ["http://localhost:3000/api/auth/sign-in/callback/oidc/keycloak"],
"webOrigins": ["http://localhost:3000"],
"redirectUris": ["http://localhost:8080/api/auth/oidc/sign-in-callback/keycloak"],
"webOrigins": ["http://localhost:8080"],
"notBefore": 0,
"bearerOnly": false,
"consentRequired": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/shield/src/actions/sign_in_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ impl SignInCallbackAction {
}

pub fn condition<P: Provider>(_provider: &P, _session: Session) -> Result<bool, ShieldError> {
Ok(false)
Ok(true)
}
}
4 changes: 3 additions & 1 deletion packages/core/shield/src/response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[derive(Clone, Debug)]
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum Response {
// TODO: Remove temporary default variant.
Default,
Expand Down
21 changes: 15 additions & 6 deletions packages/core/shield/src/shield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ use futures::future::try_join_all;
use tracing::warn;

use crate::{
ActionError, ActionProviderForm, MethodError, ProviderError, Request, action::ActionForms,
error::ShieldError, method::ErasedMethod, options::ShieldOptions, session::Session,
storage::Storage, user::User,
action::{ActionForms, ActionProviderForm},
error::{ActionError, MethodError, ProviderError, ShieldError},
method::ErasedMethod,
options::ShieldOptions,
request::Request,
response::Response,
session::Session,
storage::Storage,
user::User,
};

#[derive(Clone)]
Expand Down Expand Up @@ -121,7 +127,7 @@ impl<U: User> Shield<U> {
provider_id: Option<&str>,
session: Session,
request: Request,
) -> Result<(), ShieldError> {
) -> Result<Response, ShieldError> {
let method =
self.method_by_id(method_id)
.ok_or(ShieldError::Method(MethodError::NotFound(
Expand All @@ -142,9 +148,12 @@ impl<U: User> Shield<U> {
provider_id.map(ToOwned::to_owned),
)))?;

action.erased_call(provider, session, request).await?;
let response = action.erased_call(provider, session.clone(), request).await;

Ok(())
// TODO: Should update always be called?
session.update().await?;

response
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/core/shield/src/shield_dyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{any::Any, sync::Arc};
use async_trait::async_trait;

use crate::{
action::ActionForms, error::ShieldError, request::Request, session::Session, shield::Shield,
user::User,
action::ActionForms, error::ShieldError, request::Request, response::Response,
session::Session, shield::Shield, user::User,
};

#[async_trait]
Expand All @@ -24,7 +24,7 @@ pub trait DynShield: Send + Sync {
provider_id: Option<&str>,
session: Session,
request: Request,
) -> Result<(), ShieldError>;
) -> Result<Response, ShieldError>;
}

#[async_trait]
Expand All @@ -48,7 +48,7 @@ impl<U: User> DynShield for Shield<U> {
provider_id: Option<&str>,
session: Session,
request: Request,
) -> Result<(), ShieldError> {
) -> Result<Response, ShieldError> {
self.call(action_id, method_id, provider_id, session, request)
.await
}
Expand Down Expand Up @@ -80,7 +80,7 @@ impl ShieldDyn {
provider_id: Option<&str>,
session: Session,
request: Request,
) -> Result<(), ShieldError> {
) -> Result<Response, ShieldError> {
self.0
.call(action_id, method_id, provider_id, session, request)
.await
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/shield-axum/src/routes/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub async fn action<U: User>(

shield
.call(
&method_id,
&action_id,
&method_id,
provider_id.as_deref(),
session,
Request { query, form_data },
Expand Down
10 changes: 5 additions & 5 deletions packages/integrations/shield-dioxus/src/routes/action.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dioxus::prelude::*;
use shield::ActionForms;
use shield::{ActionForms, Response};

use crate::ErasedDioxusStyle;

Expand Down Expand Up @@ -56,20 +56,20 @@ pub async fn call(
action_id: String,
method_id: String,
provider_id: Option<String>,
) -> Result<(), ServerFnError> {
) -> Result<Response, ServerFnError> {
#[cfg(feature = "server")]
{
use dioxus::prelude::{FromContext, extract};
use serde_json::Value;
use shield::Request;
use shield::{Request, Response};

use crate::integration::DioxusIntegrationDyn;

let FromContext(integration): FromContext<DioxusIntegrationDyn> = extract().await?;
let shield = integration.extract_shield().await;
let session = integration.extract_session().await;

shield
let response = shield
.call(
&action_id,
&method_id,
Expand All @@ -83,7 +83,7 @@ pub async fn call(
)
.await?;

Ok(())
Ok(response)
}

#[cfg(not(feature = "server"))]
Expand Down
11 changes: 9 additions & 2 deletions packages/integrations/shield-leptos/src/routes/action.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use leptos::prelude::*;
use leptos_router::{hooks::use_params, params::Params};
use shield::ActionForms;
use shield::{ActionForms, Response};

use crate::ErasedLeptosStyle;

Expand Down Expand Up @@ -62,7 +62,7 @@ pub async fn call(
let shield = integration.extract_shield().await;
let session = integration.extract_session().await;

shield
let response = shield
.call(
&action_id,
&method_id,
Expand All @@ -76,5 +76,12 @@ pub async fn call(
)
.await?;

match response {
Response::Default => todo!("default reponse"),
Response::Redirect(to) => {
integration.redirect(&to);
}
}

Ok(())
}
14 changes: 13 additions & 1 deletion packages/styles/shield-bootstrap/src/dioxus/form.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dioxus::{logger::tracing::info, prelude::*};
use shield::ActionProviderForm;
use shield::{ActionProviderForm, Response};
use shield_dioxus::call;

use crate::dioxus::input::FormInput;
Expand All @@ -12,6 +12,8 @@ pub struct FormProps {

#[component]
pub fn Form(props: FormProps) -> Element {
let navigator = navigator();

rsx! {
form {
onsubmit: {
Expand All @@ -27,6 +29,16 @@ pub fn Form(props: FormProps) -> Element {

let result = call(action_id, method_id, provider_id).await;
info!("{:?}", result);

// TODO: Handle error.
if let Ok(response) = result {
match response {
Response::Default => todo!("default response"),
Response::Redirect(to) => {
navigator.push(to);
},
}
}
}
}
},
Expand Down