Skip to content

fix(OIDC): preserve existing OAuth user roles instead of resetting to default #1356

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

Merged
merged 2 commits into from
Jun 24, 2025
Merged
Changes from 1 commit
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
23 changes: 16 additions & 7 deletions src/handlers/http/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,27 @@ pub async fn reply_login(
}
}
}

// Check if user already exists to preserve their existing roles
let existing_user = Users.get_user(&username);
if !role_exists || group.is_empty() {
group = DEFAULT_ROLE
.lock()
.unwrap()
.clone()
.map(|role| HashSet::from([role]))
.unwrap_or_default();
group = if let Some(existing_user) = &existing_user {
// Preserve existing user roles instead of assigning default
existing_user.roles.clone()
} else {
// Only assign default role for new users
DEFAULT_ROLE
.lock()
.unwrap()
.clone()
.map(|role| HashSet::from([role]))
.unwrap_or_default()
};
}

// User may not exist
// create a new one depending on state of metadata
let user = match (Users.get_user(&username), group) {
let user = match (existing_user, group) {
(Some(user), group) => update_user_if_changed(user, group, user_info).await?,
(None, group) => put_user(&username, group, user_info).await?,
};
Expand Down
Loading