Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ fn create_default_database(configuration_directory: &Path) -> String {
}

#[cfg(any(test, not(feature = "lambda-web")))]
fn encode_uri(path: &Path) -> std::borrow::Cow<str> {
fn encode_uri(path: &Path) -> std::borrow::Cow<'_, str> {
const ASCII_SET: &percent_encoding::AsciiSet = &percent_encoding::NON_ALPHANUMERIC
.remove(b'-')
.remove(b'_')
Expand Down
2 changes: 1 addition & 1 deletion src/template_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ mod tests {
}
}

fn as_args(contents: &Value) -> [PathAndJson; 1] {
fn as_args(contents: &Value) -> [PathAndJson<'_>; 1] {
[as_helper_arg(CONTENT_KEY, contents)]
}

Expand Down
31 changes: 30 additions & 1 deletion src/webserver/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,29 @@ where
}
})
}

fn handle_authenticated_oidc_callback(
request: ServiceRequest,
) -> LocalBoxFuture<Result<ServiceResponse<BoxBody>, Error>> {
Box::pin(async move {
log::debug!("Handling OIDC callback for already authenticated user");

// Try to get the initial URL from the state cookie
let redirect_url = match get_state_from_cookie(&request) {
Ok(state) => {
log::debug!("Found initial URL in state: {}", state.initial_url);
state.initial_url
}
Err(e) => {
log::debug!("Could not get state from cookie (user might have been redirected from elsewhere): {e}. Redirecting to /");
"/".to_string()
}
};

let response = build_redirect_response(redirect_url);
Ok(request.into_response(response))
})
}
}

impl<S> Service<ServiceRequest> for OidcService<S>
Expand All @@ -268,6 +291,12 @@ where
fn call(&self, request: ServiceRequest) -> Self::Future {
log::trace!("Started OIDC middleware request handling");

// Handle OIDC callback URL even for authenticated users
if request.path() == SQLPAGE_REDIRECT_URI {
log::debug!("The request is the OIDC callback for an authenticated user");
return Self::handle_authenticated_oidc_callback(request);
}

let oidc_client = Arc::clone(&self.oidc_state.client);
match get_authenticated_user_info(&oidc_client, &request) {
Ok(Some(claims)) => {
Expand Down Expand Up @@ -650,7 +679,7 @@ impl OidcLoginState {
}
}

fn create_state_cookie(request: &ServiceRequest, auth_url: AuthUrlParams) -> Cookie {
fn create_state_cookie(request: &ServiceRequest, auth_url: AuthUrlParams) -> Cookie<'_> {
let state = OidcLoginState::new(request, auth_url);
let state_json = serde_json::to_string(&state).unwrap();
Cookie::build(SQLPAGE_STATE_COOKIE_NAME, state_json)
Expand Down