mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
feat(admin): remove the SSO link of an account whose provider changed its subject
A sign-in with another subject of the same provider is refused, so an account whose provider re-issued the subject (a migrated or rebuilt IdP, a changed sub format) was locked out: editing the email, as the wiki advised, never touched the stored link. The edit dialog now offers "Remove SSO link" for other accounts while SSO is set up (DELETE /api/admin/users/:id/sso, audit admin.user_sso_unlink). The next SSO sign-in links again under the rules of a first one, so it still needs a verified, not self-set email. The log line names the remedy, and the wiki tells the two refusals apart. Fixes #3065
This commit is contained in:
@@ -565,6 +565,7 @@ export const adminApi = {
|
||||
deleteUser: (id: number) => apiClient.delete(`/admin/users/${id}`).then(r => r.data),
|
||||
resetUserPasskeys: (id: number) => apiClient.delete(`/admin/users/${id}/passkeys`).then(r => r.data),
|
||||
resetUserMfa: (id: number) => apiClient.delete(`/admin/users/${id}/mfa`).then(r => r.data),
|
||||
unlinkUserSso: (id: number) => apiClient.delete(`/admin/users/${id}/sso`).then(r => r.data),
|
||||
stats: () => apiClient.get('/admin/stats').then(r => r.data),
|
||||
saveDemoBaseline: () => apiClient.post('/admin/save-demo-baseline').then(r => r.data),
|
||||
getOidc: () => apiClient.get('/admin/oidc').then(r => r.data),
|
||||
|
||||
@@ -3,9 +3,14 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { useAdminUserActions } from './useAdminUserActions';
|
||||
|
||||
// FE-HOOK-ADMUSERACT-001 to FE-HOOK-ADMUSERACT-007
|
||||
// FE-HOOK-ADMUSERACT-001 to FE-HOOK-ADMUSERACT-009
|
||||
|
||||
const api = vi.hoisted(() => ({ rotateJwtSecret: vi.fn(), resetUserPasskeys: vi.fn(), resetUserMfa: vi.fn() }));
|
||||
const api = vi.hoisted(() => ({
|
||||
rotateJwtSecret: vi.fn(),
|
||||
resetUserPasskeys: vi.fn(),
|
||||
resetUserMfa: vi.fn(),
|
||||
unlinkUserSso: vi.fn(),
|
||||
}));
|
||||
vi.mock('../../api/client', () => ({ adminApi: api }));
|
||||
|
||||
const t = (key: string, params?: Record<string, unknown>) => (params ? `${key} ${JSON.stringify(params)}` : key);
|
||||
@@ -28,6 +33,7 @@ beforeEach(() => {
|
||||
api.rotateJwtSecret.mockReset().mockResolvedValue({});
|
||||
api.resetUserPasskeys.mockReset().mockResolvedValue({ deleted: 2 });
|
||||
api.resetUserMfa.mockReset().mockResolvedValue({ success: true });
|
||||
api.unlinkUserSso.mockReset().mockResolvedValue({ success: true, unlinked: true });
|
||||
});
|
||||
|
||||
describe('useAdminUserActions', () => {
|
||||
@@ -101,4 +107,26 @@ describe('useAdminUserActions', () => {
|
||||
expect(admin.toast.error).toHaveBeenCalledWith('common.error');
|
||||
expect(ok).toBe(false);
|
||||
});
|
||||
|
||||
it('FE-HOOK-ADMUSERACT-008: removing the SSO link calls the API, toasts and reports success', async () => {
|
||||
const { admin, actions } = mount();
|
||||
let ok: boolean | undefined;
|
||||
await act(async () => {
|
||||
ok = await actions.unlinkSso({ id: 11 });
|
||||
});
|
||||
expect(api.unlinkUserSso).toHaveBeenCalledWith(11);
|
||||
expect(admin.toast.success).toHaveBeenCalledWith('admin.sso.unlinkDone');
|
||||
expect(ok).toBe(true);
|
||||
});
|
||||
|
||||
it('FE-HOOK-ADMUSERACT-009: a failed SSO unlink toasts and reports failure', async () => {
|
||||
api.unlinkUserSso.mockRejectedValue(new Error('x'));
|
||||
const { admin, actions } = mount();
|
||||
let ok: boolean | undefined;
|
||||
await act(async () => {
|
||||
ok = await actions.unlinkSso({ id: 11 });
|
||||
});
|
||||
expect(admin.toast.error).toHaveBeenCalledWith('common.error');
|
||||
expect(ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,8 +12,8 @@ interface UserActionsHost {
|
||||
/**
|
||||
* The irreversible user actions behind the admin dialogs and their phone sheets:
|
||||
* rotating the JWT secret, which signs everyone out including the admin, removing a
|
||||
* user's passkeys and switching off a user's two-factor login. Each shell keeps its own
|
||||
* confirm step and busy state around them.
|
||||
* user's passkeys, switching off a user's two-factor login and removing a user's SSO
|
||||
* link. Each shell keeps its own confirm step and busy state around them.
|
||||
*/
|
||||
export function useAdminUserActions(admin: UserActionsHost, t: TranslationFn) {
|
||||
const { toast, setRotatingJwt, setShowRotateJwtModal, logout, navigate } = admin;
|
||||
@@ -55,5 +55,17 @@ export function useAdminUserActions(admin: UserActionsHost, t: TranslationFn) {
|
||||
}
|
||||
};
|
||||
|
||||
return { rotateJwt, resetPasskeys, resetMfa };
|
||||
/** Forgets the user's SSO identity so the next SSO sign-in links again (#3065); true when it worked. */
|
||||
const unlinkSso = async (user: { id: number }): Promise<boolean> => {
|
||||
try {
|
||||
await adminApi.unlinkUserSso(user.id);
|
||||
toast.success(t('admin.sso.unlinkDone'));
|
||||
return true;
|
||||
} catch {
|
||||
toast.error(t('common.error'));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return { rotateJwt, resetPasskeys, resetMfa, unlinkSso };
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
Fingerprint,
|
||||
RefreshCw,
|
||||
ShieldOff,
|
||||
Unlink,
|
||||
UserCog,
|
||||
UserPlus,
|
||||
} from 'lucide-react';
|
||||
@@ -114,14 +115,17 @@ export default function AdminUserModals({ admin, t }: AdminUserModalsProps): Rea
|
||||
rotatingJwt,
|
||||
handleCreateUser,
|
||||
handleSaveUser,
|
||||
oidcConfigured,
|
||||
} = admin;
|
||||
const { rotateJwt, resetPasskeys, resetMfa } = useAdminUserActions(admin, t);
|
||||
const { rotateJwt, resetPasskeys, resetMfa, unlinkSso } = useAdminUserActions(admin, t);
|
||||
const [showCreatePw, setShowCreatePw] = React.useState(false);
|
||||
const [showEditPw, setShowEditPw] = React.useState(false);
|
||||
// The user whose passkeys wait for the admin's answer in the confirm dialog.
|
||||
const [passkeyResetUser, setPasskeyResetUser] = React.useState<typeof editingUser>(null);
|
||||
// Same for the two-factor reset; an admin turns off their own 2FA in Settings, not here.
|
||||
const [mfaResetUser, setMfaResetUser] = React.useState<typeof editingUser>(null);
|
||||
// Same for removing the SSO link, offered only while SSO is set up (#3065).
|
||||
const [ssoUnlinkUser, setSsoUnlinkUser] = React.useState<typeof editingUser>(null);
|
||||
const uid = useId();
|
||||
const createId = `${uid}-create`;
|
||||
const editId = `${uid}-edit`;
|
||||
@@ -318,6 +322,23 @@ export default function AdminUserModals({ admin, t }: AdminUserModalsProps): Rea
|
||||
</div>
|
||||
</DialogSection>
|
||||
)}
|
||||
{oidcConfigured && editingUser && editingUser.id !== currentUser?.id && (
|
||||
<DialogSection label={t('admin.sso.unlink')}>
|
||||
<div className="flex flex-wrap items-center gap-3 rounded-[12px] border border-edge-faint bg-surface-secondary px-3.5 py-3">
|
||||
<p className="m-0 min-w-0 flex-1 basis-52 leading-snug text-content-muted" style={fs(12, 'body')}>
|
||||
{t('admin.sso.unlinkHint')}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSsoUnlinkUser(editingUser)}
|
||||
className={`${SETTINGS_BUTTON_DANGER} flex-none`}
|
||||
style={fs(12.5, 'body')}
|
||||
>
|
||||
<Unlink size={14} /> {t('admin.sso.unlink')}
|
||||
</button>
|
||||
</div>
|
||||
</DialogSection>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</DialogShell>
|
||||
@@ -480,6 +501,19 @@ docker run -d --name trek \\
|
||||
confirmLabel={t('admin.mfa.reset')}
|
||||
danger
|
||||
/>
|
||||
|
||||
<ConfirmDialog
|
||||
isOpen={ssoUnlinkUser !== null}
|
||||
onClose={() => setSsoUnlinkUser(null)}
|
||||
onConfirm={async () => {
|
||||
if (!ssoUnlinkUser) return;
|
||||
await unlinkSso(ssoUnlinkUser);
|
||||
}}
|
||||
title={t('admin.sso.unlink')}
|
||||
message={ssoUnlinkUser ? t('admin.sso.unlinkConfirm', { name: ssoUnlinkUser.username }) : ''}
|
||||
confirmLabel={t('admin.sso.unlink')}
|
||||
danger
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user