fix: admin role mapping grants only, revoke behind opt-in
SSO login for an existing admin whose token lacked the admin role was silently demoting the account, locking admins out of the dashboard. Missing admin role now leaves the flag alone unless RevokeAdminWithoutRole is enabled. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -143,9 +143,16 @@ public class OidcAuthController : ControllerBase
|
||||
var adminRoles = SplitCsv(Config.AdminRoles);
|
||||
if (adminRoles.Length > 0)
|
||||
{
|
||||
var isAdmin = roles.Intersect(adminRoles, StringComparer.OrdinalIgnoreCase).Any();
|
||||
_logger.LogInformation("OIDC admin mapping for {Username}: admin roles [{AdminRoles}] => admin={IsAdmin}", username, Config.AdminRoles, isAdmin);
|
||||
user.SetPermission(PermissionKind.IsAdministrator, isAdmin);
|
||||
var hasAdminRole = roles.Intersect(adminRoles, StringComparer.OrdinalIgnoreCase).Any();
|
||||
_logger.LogInformation("OIDC admin mapping for {Username}: admin roles [{AdminRoles}] => hasAdminRole={HasAdminRole}", username, Config.AdminRoles, hasAdminRole);
|
||||
if (hasAdminRole)
|
||||
{
|
||||
user.SetPermission(PermissionKind.IsAdministrator, true);
|
||||
}
|
||||
else if (Config.RevokeAdminWithoutRole)
|
||||
{
|
||||
user.SetPermission(PermissionKind.IsAdministrator, false);
|
||||
}
|
||||
}
|
||||
|
||||
await _userManager.UpdateUserAsync(user).ConfigureAwait(false);
|
||||
|
||||
Reference in New Issue
Block a user