Skip to content

Commit

Permalink
refactor: tweak a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Nov 16, 2023
1 parent d7e29d9 commit d51af31
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,31 @@ use yew::Callback;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct LoginOptions {
pub query: HashMap<String, String>,
/// 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<Url>,
}

impl LoginOptions {
pub fn new() -> Self {
LoginOptions::default()
}
pub fn with_query(mut self, query: HashMap<String, String>) -> Self {
self.query = query;

pub fn with_query(mut self, query: impl IntoIterator<Item = (String, String)>) -> Self {
self.query = HashMap::from_iter(query);
self
}
pub fn with_extended_query(mut self, query: HashMap<String, String>) -> Self {

pub fn with_extended_query(
mut self,
query: impl IntoIterator<Item = (String, String)>,
) -> Self {
self.query.extend(query);
self
}

pub fn with_redirect_url(mut self, redirect_url: Url) -> Self {
self.redirect_url = Some(redirect_url);
self
Expand Down Expand Up @@ -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())?;

Expand Down

0 comments on commit d51af31

Please sign in to comment.