diff --git a/src/agent/mod.rs b/src/agent/mod.rs index 5a367dc..7b766f1 100644 --- a/src/agent/mod.rs +++ b/src/agent/mod.rs @@ -28,7 +28,10 @@ use yew::Callback; #[derive(Debug, Clone, Default, PartialEq, Eq)] pub struct LoginOptions { pub query: HashMap, - /// Defines the redirect URL. If thsi field is empty, the current URL is used as a redirect URL. + + /// Defines the redirect URL. + /// + /// If this field is empty, the current URL is used as a redirect URL. pub redirect_url: Option, } @@ -36,14 +39,20 @@ impl LoginOptions { pub fn new() -> Self { LoginOptions::default() } - pub fn with_query(mut self, query: HashMap) -> Self { - self.query = query; + + pub fn with_query(mut self, query: impl IntoIterator) -> Self { + self.query = HashMap::from_iter(query); self } - pub fn with_extended_query(mut self, query: HashMap) -> Self { + + pub fn with_extended_query( + mut self, + query: impl IntoIterator, + ) -> Self { self.query.extend(query); self } + pub fn with_redirect_url(mut self, redirect_url: Url) -> Self { self.redirect_url = Some(redirect_url); self @@ -424,9 +433,10 @@ where fn start_login(&mut self, options: LoginOptions) -> Result<(), OAuth2Error> { let client = self.client.as_ref().ok_or(OAuth2Error::NotInitialized)?; let config = self.config.as_ref().ok_or(OAuth2Error::NotInitialized)?; - let redirect_url = options - .redirect_url - .unwrap_or(Self::current_url().map_err(OAuth2Error::StartLogin)?); + let redirect_url = match options.redirect_url { + Some(redirect_url) => redirect_url, + None => Self::current_url().map_err(OAuth2Error::StartLogin)?, + }; let login_context = client.make_login_context(config, redirect_url.clone())?;