Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable redirect URL through LoginOptions #20

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ 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.
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;
self
}
pub fn with_extended_query(mut self, query: HashMap<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
}
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -404,7 +424,9 @@ 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 = Self::current_url().map_err(OAuth2Error::StartLogin)?;
let redirect_url = options
.redirect_url
.unwrap_or(Self::current_url().map_err(OAuth2Error::StartLogin)?);

let login_context = client.make_login_context(config, redirect_url.clone())?;

Expand Down