From 2a57b85a284d453f93aa8c1c01a23afa04057ee6 Mon Sep 17 00:00:00 2001 From: mh84 Date: Mon, 2 Oct 2023 17:13:49 +0200 Subject: [PATCH 1/2] add default LoginOptions to OAuth2 --- src/agent/config.rs | 3 +++ src/agent/mod.rs | 5 +++++ src/components/context/mod.rs | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/src/agent/config.rs b/src/agent/config.rs index 2bfc3d2..b1fa3e6 100644 --- a/src/agent/config.rs +++ b/src/agent/config.rs @@ -1,12 +1,15 @@ use crate::agent::Client; use std::time::Duration; +use super::LoginOptions; + #[derive(Clone, Debug)] pub struct AgentConfiguration { pub config: C::Configuration, pub scopes: Vec, pub grace_period: Duration, pub audience: Option, + pub options: Option, } impl PartialEq for AgentConfiguration { diff --git a/src/agent/mod.rs b/src/agent/mod.rs index 9deb798..25d2d70 100644 --- a/src/agent/mod.rs +++ b/src/agent/mod.rs @@ -91,6 +91,7 @@ pub struct InnerConfig { scopes: Vec, grace_period: Duration, audience: Option, + options: Option, } impl InnerAgent @@ -230,6 +231,7 @@ where scopes: config.scopes, grace_period: config.grace_period, audience: config.audience, + options: config.options, }; Ok((client, inner)) @@ -418,6 +420,9 @@ where let mut login_url = login_context.url; login_url.query_pairs_mut().extend_pairs(options.query); + if let Some(options) = &config.options { + login_url.query_pairs_mut().extend_pairs(options.query.clone()); + } // the next call will most likely navigate away from this page diff --git a/src/components/context/mod.rs b/src/components/context/mod.rs index a2c25fc..ca62602 100644 --- a/src/components/context/mod.rs +++ b/src/components/context/mod.rs @@ -5,6 +5,7 @@ mod agent; pub use agent::*; use crate::context::LatestAccessToken; +use crate::prelude::LoginOptions; use crate::{ agent::{AgentConfiguration, Client, OAuth2Operations}, context::OAuth2Context, @@ -36,6 +37,10 @@ pub struct Props { /// Children which will have access to the [`OAuth2Context`]. #[prop_or_default] pub children: Children, + + /// Default [`LoginOptions`] that will be used for every request + #[prop_or_default] + pub options: Option, } impl PartialEq for Props { @@ -130,6 +135,7 @@ impl OAuth2 { scopes: props.scopes.clone(), grace_period: props.grace_period, audience: props.audience.clone(), + options: props.options.clone(), } } } From c0325ccd4859e1a856aae7fbfacd7a28969d52e5 Mon Sep 17 00:00:00 2001 From: mh84 Date: Mon, 2 Oct 2023 18:03:38 +0200 Subject: [PATCH 2/2] cargo fmt --- src/agent/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/agent/mod.rs b/src/agent/mod.rs index 25d2d70..af3477e 100644 --- a/src/agent/mod.rs +++ b/src/agent/mod.rs @@ -421,7 +421,9 @@ where login_url.query_pairs_mut().extend_pairs(options.query); if let Some(options) = &config.options { - login_url.query_pairs_mut().extend_pairs(options.query.clone()); + login_url + .query_pairs_mut() + .extend_pairs(options.query.clone()); } // the next call will most likely navigate away from this page