Skip to content

Commit

Permalink
Allow user to store the current url in the session before going to th…
Browse files Browse the repository at this point in the history
…e IDP
  • Loading branch information
AlexandreRoba authored and kate-shine committed Jan 25, 2024
1 parent 066e0d7 commit 4ac9647
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ where
let client = self.client.as_ref().ok_or(OAuth2Error::NotInitialized)?;
let config = self.config.as_ref().ok_or(OAuth2Error::NotInitialized)?;

let post_login_url = Self::current_url().map_err(OAuth2Error::StartLogin)?;

// take the parameter value first, then the agent configured value, then fall back to the default
let redirect_url = match options.redirect_url.or_else(|| {
config
Expand All @@ -471,6 +473,11 @@ where
None => Self::current_url().map_err(OAuth2Error::StartLogin)?,
};

if redirect_url != post_login_url {
SessionStorage::set(STORAGE_KEY_POST_LOGIN_URL, post_login_url)
.map_err(|err| OAuth2Error::StartLogin(err.to_string()))?;
}

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

SessionStorage::set(STORAGE_KEY_CSRF_TOKEN, login_context.csrf_token)
Expand Down
1 change: 1 addition & 0 deletions src/agent/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub const STORAGE_KEY_CSRF_TOKEN: &str = "ctron/oauth2/csrfToken";
pub const STORAGE_KEY_LOGIN_STATE: &str = "ctron/oauth2/loginState";
pub const STORAGE_KEY_REDIRECT_URL: &str = "ctron/oauth2/redirectUrl";
pub const STORAGE_KEY_POST_LOGIN_URL: &str = "ctron/oauth2/postLoginUrl";

#[derive(Debug)]
pub struct State {
Expand Down

0 comments on commit 4ac9647

Please sign in to comment.