Skip to content

Commit f796fce

Browse files
feat: add action call response (#160)
1 parent 628932d commit f796fce

14 files changed

Lines changed: 66 additions & 30 deletions

File tree

examples/axum/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async fn main() {
4343
)
4444
.client_secret("xcpQsaGbRILTljPtX4npjmYMBjKrariJ")
4545
.redirect_url(format!(
46-
"http://localhost:{}/api/auth/sign-in/callback/oidc/keycloak",
46+
"http://localhost:{}/api/auth/oidc/sign-in-callback/keycloak",
4747
addr.port()
4848
))
4949
.build()]),

examples/dioxus-axum/src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ async fn main() {
3232
use tracing::{Level, info};
3333

3434
// Initialize Dioxus
35-
let addr = fullstack_address_or_localhost();
3635
dioxus::logger::init(Level::DEBUG).unwrap();
36+
let addr = fullstack_address_or_localhost();
3737

3838
// Initialize sessions
3939
let session_store = MemoryStore::default();
@@ -53,8 +53,10 @@ async fn main() {
5353
)
5454
.client_secret("xcpQsaGbRILTljPtX4npjmYMBjKrariJ")
5555
.redirect_url(format!(
56-
"http://localhost:{}/api/auth/sign-in/callback/oidc/keycloak",
57-
addr.port()
56+
"http://localhost:{}/api/auth/oidc/sign-in-callback/keycloak",
57+
dioxus::cli_config::devserver_raw_addr()
58+
.map(|addr| addr.port())
59+
.unwrap_or_else(|| addr.port())
5860
))
5961
.build()]),
6062
)],

examples/leptos-actix/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ bin-default-features = false
1616
lib-features = ["hydrate"]
1717
lib-default-features = false
1818

19+
site-addr = "127.0.0.1:8080"
20+
1921
[lib]
2022
crate-type = ["cdylib", "rlib"]
2123

examples/leptos-axum/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ bin-default-features = false
1616
lib-features = ["hydrate"]
1717
lib-default-features = false
1818

19+
site-addr = "127.0.0.1:8080"
20+
1921
[lib]
2022
crate-type = ["cdylib", "rlib"]
2123

examples/leptos-axum/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async fn main() {
5151
)
5252
.client_secret("xcpQsaGbRILTljPtX4npjmYMBjKrariJ")
5353
.redirect_url(format!(
54-
"http://localhost:{}/api/auth/sign-in/callback/oidc/keycloak",
54+
"http://localhost:{}/api/auth/oidc/sign-in-callback/keycloak",
5555
addr.port()
5656
))
5757
.build()]),

keycloak/Shield-realm.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,14 +612,14 @@
612612
"description": "",
613613
"rootUrl": "",
614614
"adminUrl": "",
615-
"baseUrl": "http://localhost:3000",
615+
"baseUrl": "http://localhost:8080",
616616
"surrogateAuthRequired": false,
617617
"enabled": true,
618618
"alwaysDisplayInConsole": false,
619619
"clientAuthenticatorType": "client-secret",
620620
"secret": "xcpQsaGbRILTljPtX4npjmYMBjKrariJ",
621-
"redirectUris": ["http://localhost:3000/api/auth/sign-in/callback/oidc/keycloak"],
622-
"webOrigins": ["http://localhost:3000"],
621+
"redirectUris": ["http://localhost:8080/api/auth/oidc/sign-in-callback/keycloak"],
622+
"webOrigins": ["http://localhost:8080"],
623623
"notBefore": 0,
624624
"bearerOnly": false,
625625
"consentRequired": false,

packages/core/shield/src/actions/sign_in_callback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ impl SignInCallbackAction {
1515
}
1616

1717
pub fn condition<P: Provider>(_provider: &P, _session: Session) -> Result<bool, ShieldError> {
18-
Ok(false)
18+
Ok(true)
1919
}
2020
}

packages/core/shield/src/response.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#[derive(Clone, Debug)]
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Clone, Debug, Deserialize, Serialize)]
24
pub enum Response {
35
// TODO: Remove temporary default variant.
46
Default,

packages/core/shield/src/shield.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ use futures::future::try_join_all;
44
use tracing::warn;
55

66
use crate::{
7-
ActionError, ActionProviderForm, MethodError, ProviderError, Request, action::ActionForms,
8-
error::ShieldError, method::ErasedMethod, options::ShieldOptions, session::Session,
9-
storage::Storage, user::User,
7+
action::{ActionForms, ActionProviderForm},
8+
error::{ActionError, MethodError, ProviderError, ShieldError},
9+
method::ErasedMethod,
10+
options::ShieldOptions,
11+
request::Request,
12+
response::Response,
13+
session::Session,
14+
storage::Storage,
15+
user::User,
1016
};
1117

1218
#[derive(Clone)]
@@ -121,7 +127,7 @@ impl<U: User> Shield<U> {
121127
provider_id: Option<&str>,
122128
session: Session,
123129
request: Request,
124-
) -> Result<(), ShieldError> {
130+
) -> Result<Response, ShieldError> {
125131
let method =
126132
self.method_by_id(method_id)
127133
.ok_or(ShieldError::Method(MethodError::NotFound(
@@ -142,9 +148,12 @@ impl<U: User> Shield<U> {
142148
provider_id.map(ToOwned::to_owned),
143149
)))?;
144150

145-
action.erased_call(provider, session, request).await?;
151+
let response = action.erased_call(provider, session.clone(), request).await;
146152

147-
Ok(())
153+
// TODO: Should update always be called?
154+
session.update().await?;
155+
156+
response
148157
}
149158
}
150159

packages/core/shield/src/shield_dyn.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::{any::Any, sync::Arc};
33
use async_trait::async_trait;
44

55
use crate::{
6-
action::ActionForms, error::ShieldError, request::Request, session::Session, shield::Shield,
7-
user::User,
6+
action::ActionForms, error::ShieldError, request::Request, response::Response,
7+
session::Session, shield::Shield, user::User,
88
};
99

1010
#[async_trait]
@@ -24,7 +24,7 @@ pub trait DynShield: Send + Sync {
2424
provider_id: Option<&str>,
2525
session: Session,
2626
request: Request,
27-
) -> Result<(), ShieldError>;
27+
) -> Result<Response, ShieldError>;
2828
}
2929

3030
#[async_trait]
@@ -48,7 +48,7 @@ impl<U: User> DynShield for Shield<U> {
4848
provider_id: Option<&str>,
4949
session: Session,
5050
request: Request,
51-
) -> Result<(), ShieldError> {
51+
) -> Result<Response, ShieldError> {
5252
self.call(action_id, method_id, provider_id, session, request)
5353
.await
5454
}
@@ -80,7 +80,7 @@ impl ShieldDyn {
8080
provider_id: Option<&str>,
8181
session: Session,
8282
request: Request,
83-
) -> Result<(), ShieldError> {
83+
) -> Result<Response, ShieldError> {
8484
self.0
8585
.call(action_id, method_id, provider_id, session, request)
8686
.await

0 commit comments

Comments
 (0)