mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-07-15 04:43:36 +00:00
feat: sync admin status from OIDC group membership on login
This commit is contained in:
@@ -521,6 +521,7 @@ router.post("/oidc-config", authenticateJWT, async (req, res) => {
|
|||||||
name_path,
|
name_path,
|
||||||
scopes,
|
scopes,
|
||||||
allowed_users,
|
allowed_users,
|
||||||
|
admin_group,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
const isDisableRequest =
|
const isDisableRequest =
|
||||||
@@ -579,6 +580,7 @@ router.post("/oidc-config", authenticateJWT, async (req, res) => {
|
|||||||
name_path,
|
name_path,
|
||||||
scopes: scopes || "openid email profile",
|
scopes: scopes || "openid email profile",
|
||||||
allowed_users: allowed_users || "",
|
allowed_users: allowed_users || "",
|
||||||
|
admin_group: admin_group || "",
|
||||||
};
|
};
|
||||||
|
|
||||||
let encryptedConfig;
|
let encryptedConfig;
|
||||||
@@ -1300,8 +1302,26 @@ router.get("/oidc/callback", async (req, res) => {
|
|||||||
|
|
||||||
const userRecord = user[0];
|
const userRecord = user[0];
|
||||||
|
|
||||||
|
// Sync admin status based on OIDC group membership
|
||||||
|
if (config.admin_group) {
|
||||||
|
const groups = (userInfo.groups || userInfo.roles || []) as string[];
|
||||||
|
const shouldBeAdmin = groups.includes(config.admin_group);
|
||||||
|
if (!!userRecord.isAdmin !== shouldBeAdmin) {
|
||||||
|
await db
|
||||||
|
.update(users)
|
||||||
|
.set({ isAdmin: shouldBeAdmin })
|
||||||
|
.where(eq(users.id, userRecord.id));
|
||||||
|
userRecord.isAdmin = shouldBeAdmin;
|
||||||
|
authLogger.info("OIDC admin status synced", {
|
||||||
|
operation: "oidc_admin_group_sync",
|
||||||
|
userId: userRecord.id,
|
||||||
|
group: config.admin_group,
|
||||||
|
isAdmin: shouldBeAdmin,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await authManager.authenticateOIDCUser(userRecord.id, deviceInfo.type);
|
|
||||||
} catch (setupError) {
|
} catch (setupError) {
|
||||||
authLogger.error("Failed to setup OIDC user encryption", setupError, {
|
authLogger.error("Failed to setup OIDC user encryption", setupError, {
|
||||||
operation: "oidc_user_encryption_setup_failed",
|
operation: "oidc_user_encryption_setup_failed",
|
||||||
|
|||||||
Reference in New Issue
Block a user