Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Add OIDC scope editing to SSO provider settings

rcourtman87aac4e5758f
diff --git a/frontend-modern/src/components/Settings/SSOProvidersPanel.tsx b/frontend-modern/src/components/Settings/SSOProvidersPanel.tsx
index b2e41e8260..cf1af45ae9 100644
--- a/frontend-modern/src/components/Settings/SSOProvidersPanel.tsx
+++ b/frontend-modern/src/components/Settings/SSOProvidersPanel.tsx
@@ -333,6 +333,21 @@ export const SSOProvidersPanel: Component<SSOProvidersPanelProps> = (props) => {
/>
</div>
</div>
+
+ <div class={formField}>
+ <label class={labelClass()}>Scopes</label>
+ <input
+ type="text"
+ value={form.oidcScopes}
+ onInput={(e) => setForm('oidcScopes', e.currentTarget.value)}
+ placeholder="openid profile email"
+ class={controlClass()}
+ />
+ <p class={formHelpText}>
+ Space-separated scopes for the sign-in request. Some IdPs only return group
+ claims when an extra scope (e.g. groups) is requested here.
+ </p>
+ </div>
</div>
</Show>
@@ -599,7 +614,9 @@ export const SSOProvidersPanel: Component<SSOProvidersPanelProps> = (props) => {
class={controlClass()}
/>
<p class={formHelpText}>
- Claim used for OIDC allowed groups and role mappings.
+ Claim used for OIDC allowed groups and role mappings. If your IdP only
+ returns groups when asked, add the matching scope in the Scopes field
+ above.
</p>
</div>
</Show>
diff --git a/frontend-modern/src/components/Settings/__tests__/SSOProvidersPanel.test.tsx b/frontend-modern/src/components/Settings/__tests__/SSOProvidersPanel.test.tsx
new file mode 100644
index 0000000000..be45f97aca
--- /dev/null
+++ b/frontend-modern/src/components/Settings/__tests__/SSOProvidersPanel.test.tsx
@@ -0,0 +1,138 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
+import { SSOProvidersPanel } from '../SSOProvidersPanel';
+
+const fetchMock = vi.fn();
+const notificationSuccessMock = vi.fn();
+const notificationErrorMock = vi.fn();
+const loggerErrorMock = vi.fn();
+const loggerWarnMock = vi.fn();
+
+vi.mock('@/stores/notifications', () => ({
+ notificationStore: {
+ success: (...args: unknown[]) => notificationSuccessMock(...args),
+ error: (...args: unknown[]) => notificationErrorMock(...args),
+ },
+}));
+
+vi.mock('@/utils/logger', () => ({
+ logger: {
+ error: (...args: unknown[]) => loggerErrorMock(...args),
+ warn: (...args: unknown[]) => loggerWarnMock(...args),
+ },
+}));
+
+const jsonResponse = (body: unknown) =>
+ new Response(JSON.stringify(body), {
+ status: 200,
+ headers: { 'Content-Type': 'application/json' },
+ });
+
+const corpProvider = {
+ id: 'corp-oidc',
+ name: 'Corporate OIDC',
+ type: 'oidc' as const,
+ enabled: true,
+ priority: 0,
+};
+
+const corpProviderDetails = {
+ id: 'corp-oidc',
+ name: 'Corporate OIDC',
+ type: 'oidc' as const,
+ enabled: true,
+ oidc: {
+ issuerUrl: 'https://idp.example.com',
+ clientId: 'pulse',
+ scopes: ['openid', 'profile', 'email', 'groups'],
+ },
+ groupsClaim: 'groups',
+ allowedGroups: ['admins'],
+ groupRoleMappings: { admins: 'admin' },
+};
+
+const setupFetch = (providers: unknown[]) => {
+ fetchMock.mockImplementation((url: string, options?: RequestInit) => {
+ const method = (options?.method ?? 'GET').toUpperCase();
+ if (url === '/api/security/sso/providers' && method === 'GET') {
+ return Promise.resolve(jsonResponse({ providers, allowMultipleProviders: false }));
+ }
+ if (url === '/api/security/status') {
+ return Promise.resolve(jsonResponse({ publicUrl: 'https://pulse.example.com' }));
+ }
+ if (url === '/api/security/sso/providers/corp-oidc' && method === 'GET') {
+ return Promise.resolve(jsonResponse(corpProviderDetails));
+ }
+ if (method === 'POST' || method === 'PUT') {
+ return Promise.resolve(jsonResponse({ id: 'corp-oidc' }));
+ }
+ return Promise.resolve(jsonResponse({}));
+ });
+};
+
+const scopesInput = () => screen.getByPlaceholderText('openid profile email') as HTMLInputElement;
+
+describe('SSOProvidersPanel OIDC scopes', () => {
+ beforeEach(() => {
+ fetchMock.mockReset();
+ notificationSuccessMock.mockReset();
+ notificationErrorMock.mockReset();
+ loggerErrorMock.mockReset();
+ loggerWarnMock.mockReset();
+ vi.stubGlobal('fetch', fetchMock);
+ document.cookie = 'pulse_csrf=test-csrf-token';
+ });
+
+ afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ });
+
+ it('lets an admin create an OIDC provider with a custom scope set', async () => {
+ setupFetch([]);
+ render(() => <SSOProvidersPanel />);
+
+ const addButton = await screen.findByRole('button', { name: /Add OIDC/i });
+ fireEvent.click(addButton);
+
+ const scopes = scopesInput();
+ expect(scopes.value).toBe('openid profile email');
+
+ fireEvent.input(screen.getByPlaceholderText('e.g., Corporate SSO'), {
+ target: { value: 'Corporate OIDC' },
+ });
+ fireEvent.input(screen.getByPlaceholderText('https://login.example.com/realms/pulse'), {
+ target: { value: 'https://idp.example.com' },
+ });
+ fireEvent.input(screen.getByPlaceholderText('pulse-client'), {
+ target: { value: 'pulse' },
+ });
+ fireEvent.input(scopes, { target: { value: 'openid profile email groups' } });
+
+ const submitButton = screen.getByRole('button', { name: 'Create Provider' });
+ fireEvent.submit(submitButton.closest('form')!);
+
+ await waitFor(() => {
+ const createCall = fetchMock.mock.calls.find(
+ ([url, options]) =>
+ url === '/api/security/sso/providers' &&
+ (options as RequestInit | undefined)?.method === 'POST',
+ );
+ expect(createCall).toBeTruthy();
+ const body = JSON.parse((createCall![1] as RequestInit).body as string);
+ expect(body.oidc.scopes).toEqual(['openid', 'profile', 'email', 'groups']);
+ });
+ });
+
+ it('shows the saved scope set when reopening a provider for editing', async () => {
+ setupFetch([corpProvider]);
+ render(() => <SSOProvidersPanel />);
+
+ const editButton = await screen.findByRole('button', { name: 'Edit provider' });
+ fireEvent.click(editButton);
+
+ await waitFor(() => {
+ expect(scopesInput().value).toBe('openid profile email groups');
+ });
+ });
+});
diff --git a/frontend-modern/src/components/Settings/__tests__/ssoProvidersModel.test.ts b/frontend-modern/src/components/Settings/__tests__/ssoProvidersModel.test.ts
index fa1fcec42a..c008aac6ef 100644
--- a/frontend-modern/src/components/Settings/__tests__/ssoProvidersModel.test.ts
+++ b/frontend-modern/src/components/Settings/__tests__/ssoProvidersModel.test.ts
@@ -32,6 +32,58 @@ describe('ssoProvidersModel', () => {
});
});
+ it('serializes custom OIDC scopes into the provider payload', () => {
+ const form = {
+ ...createEmptyProviderForm(),
+ name: 'Corporate OIDC',
+ type: 'oidc' as const,
+ oidcIssuerUrl: 'https://idp.example.com',
+ oidcClientId: 'pulse',
+ oidcScopes: 'openid profile email groups',
+ };
+
+ const payload = buildProviderPayload(form);
+ const oidc = payload.oidc as Record<string, unknown>;
+
+ expect(oidc.scopes).toEqual(['openid', 'profile', 'email', 'groups']);
+ });
+
+ it('maps saved OIDC scopes back into the form for editing', () => {
+ const form = mapProviderDetailsToForm({
+ id: 'corp-oidc',
+ name: 'Corporate OIDC',
+ type: 'oidc',
+ enabled: true,
+ oidc: {
+ issuerUrl: 'https://idp.example.com',
+ clientId: 'pulse',
+ scopes: ['openid', 'profile', 'email', 'groups'],
+ },
+ });
+
+ expect(form.oidcScopes).toBe('openid profile email groups');
+ });
+
+ it('defaults missing OIDC scopes to openid profile email', () => {
+ const form = mapProviderDetailsToForm({
+ id: 'corp-oidc',
+ name: 'Corporate OIDC',
+ type: 'oidc',
+ enabled: true,
+ oidc: {
+ issuerUrl: 'https://idp.example.com',
+ clientId: 'pulse',
+ },
+ });
+
+ expect(form.oidcScopes).toBe('openid profile email');
+
+ const payload = buildProviderPayload(form);
+ const oidc = payload.oidc as Record<string, unknown>;
+
+ expect(oidc.scopes).toEqual(['openid', 'profile', 'email']);
+ });
+
it('maps OIDC provider details back to the shared groups claim field', () => {
const form = mapProviderDetailsToForm({
id: 'corp-oidc',