From 787d1e1aafeb53f474e1069b39fa40ed5326c2f3 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Sat, 25 Jul 2026 16:32:23 -0500 Subject: [PATCH 1/3] fix: ensure correct url for acccount management --- .../settings/devices/OtherDevices.tsx | 10 +++++-- .../settings/devices/Verification.tsx | 8 ++++- src/app/hooks/useAccountManagement.test.ts | 30 +++++++++++++++++++ src/app/hooks/useAccountManagement.ts | 5 ++-- 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/app/hooks/useAccountManagement.test.ts diff --git a/src/app/features/settings/devices/OtherDevices.tsx b/src/app/features/settings/devices/OtherDevices.tsx index 117bc77a8..78877a492 100644 --- a/src/app/features/settings/devices/OtherDevices.tsx +++ b/src/app/features/settings/devices/OtherDevices.tsx @@ -62,7 +62,12 @@ export function OtherDevices({ devices, refreshDeviceList, showVerification }: O const [deleted, setDeleted] = useState(new Set()); const handleDashboardOIDC = useCallback(() => { - const url = getAccountManagementUrl(authMetadata, accountManagementActions.sessionsList); + const url = getAccountManagementUrl( + authMetadata, + accountManagementActions.sessionsList, + undefined, + mx.getHomeserverUrl() + ); if (!url) return; if (isTauri()) { import('@tauri-apps/plugin-opener') @@ -78,7 +83,8 @@ export function OtherDevices({ devices, refreshDeviceList, showVerification }: O const url = getAccountManagementUrl( authMetadata, accountManagementActions.sessionEnd, - deviceId + deviceId, + mx.getHomeserverUrl() ); if (!url) return; if (isTauri()) { diff --git a/src/app/features/settings/devices/Verification.tsx b/src/app/features/settings/devices/Verification.tsx index b50b01fca..990ca7aad 100644 --- a/src/app/features/settings/devices/Verification.tsx +++ b/src/app/features/settings/devices/Verification.tsx @@ -257,6 +257,7 @@ export function EnableVerification({ visible }: EnableVerificationProps) { export function DeviceVerificationOptions() { const [menuCords, setMenuCords] = useState(); const authMetadata = useAuthMetadata(); + const mx = useMatrixClient(); const accountManagementActions = useAccountManagementActions(); const [reset, setReset] = useState(false); @@ -272,7 +273,12 @@ export function DeviceVerificationOptions() { const handleReset = () => { setMenuCords(undefined); - const url = getAccountManagementUrl(authMetadata, accountManagementActions.crossSigningReset); + const url = getAccountManagementUrl( + authMetadata, + accountManagementActions.crossSigningReset, + undefined, + mx.getHomeserverUrl() + ); if (url) { if (isTauri()) { import('@tauri-apps/plugin-opener') diff --git a/src/app/hooks/useAccountManagement.test.ts b/src/app/hooks/useAccountManagement.test.ts new file mode 100644 index 000000000..a318da56e --- /dev/null +++ b/src/app/hooks/useAccountManagement.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from 'vitest'; +import type { ValidatedAuthMetadata } from '$types/matrix-sdk'; +import { getAccountManagementUrl } from './useAccountManagement'; + +const metadata = { + issuer: 'https://auth.example', + authorization_endpoint: 'https://auth.example/authorize', + token_endpoint: 'https://auth.example/token', + registration_endpoint: 'https://auth.example/register', + revocation_endpoint: 'https://auth.example/revoke', + response_types_supported: ['code'], + response_modes_supported: ['query', 'fragment'], + grant_types_supported: ['authorization_code', 'refresh_token'], + code_challenge_methods_supported: ['S256'], + account_management_uri: '/_continuwuity/', + account_management_actions_supported: ['org.matrix.devices_list'], +} as ValidatedAuthMetadata; + +describe('getAccountManagementUrl', () => { + it('resolves account paths against the discovered homeserver URL', () => { + expect( + getAccountManagementUrl( + metadata, + 'org.matrix.devices_list', + undefined, + 'https://actual-homeserver.example/matrix' + ) + ).toBe('https://actual-homeserver.example/_continuwuity/?action=org.matrix.devices_list'); + }); +}); diff --git a/src/app/hooks/useAccountManagement.ts b/src/app/hooks/useAccountManagement.ts index 4e10c4287..4456ec899 100644 --- a/src/app/hooks/useAccountManagement.ts +++ b/src/app/hooks/useAccountManagement.ts @@ -4,11 +4,12 @@ import type { ValidatedAuthMetadata } from '$types/matrix-sdk'; export const getAccountManagementUrl = ( metadata: ValidatedAuthMetadata | undefined, action: string, - deviceId?: string + deviceId?: string, + homeserverUrl?: string ): string | undefined => { if (!metadata?.account_management_uri) return undefined; - const url = new URL(metadata.account_management_uri); + const url = new URL(metadata.account_management_uri, homeserverUrl); if (metadata.account_management_actions_supported?.includes(action)) { url.searchParams.set('action', action); if (deviceId) url.searchParams.set('device_id', deviceId); From f05a11db42afb6c8813ee22dcf6a9af4ff4e8154 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Sat, 25 Jul 2026 16:56:57 -0500 Subject: [PATCH 2/3] fix: adjust login auth page flow --- src/app/components/AuthFlowsLoader.tsx | 14 +++++++-- src/app/hooks/useAuthFlows.ts | 9 ++++++ src/app/pages/auth/login/Login.tsx | 43 ++++++++++++-------------- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/app/components/AuthFlowsLoader.tsx b/src/app/components/AuthFlowsLoader.tsx index 9c0e96d33..616ccb7e4 100644 --- a/src/app/components/AuthFlowsLoader.tsx +++ b/src/app/components/AuthFlowsLoader.tsx @@ -5,8 +5,13 @@ import { createClient } from '$types/matrix-sdk'; import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback'; import { useAutoDiscoveryInfo } from '$hooks/useAutoDiscoveryInfo'; import { promiseFulfilledResult, promiseRejectedResult } from '$utils/common'; -import type { AuthFlows, RegisterFlowsResponse } from '$hooks/useAuthFlows'; -import { RegisterFlowStatus, parseRegisterErrResp } from '$hooks/useAuthFlows'; +import { + isUsableOAuthMetadata, + type AuthFlows, + RegisterFlowStatus, + parseRegisterErrResp, + type RegisterFlowsResponse, +} from '$hooks/useAuthFlows'; import { fetch } from '$utils/fetch'; type AuthFlowsLoaderProps = { @@ -29,7 +34,10 @@ export function AuthFlowsLoader({ fallback, error, children }: AuthFlowsLoaderPr ]); const loginFlows = promiseFulfilledResult(result[0]); const registerResp = promiseRejectedResult(result[1]) as MatrixError | undefined; - const authMetadata = promiseFulfilledResult(result[2]); + const discoveredAuthMetadata = promiseFulfilledResult(result[2]); + const authMetadata = isUsableOAuthMetadata(discoveredAuthMetadata) + ? discoveredAuthMetadata + : undefined; let registerFlows: RegisterFlowsResponse = { status: RegisterFlowStatus.InvalidRequest, }; diff --git a/src/app/hooks/useAuthFlows.ts b/src/app/hooks/useAuthFlows.ts index c7f9d82c6..5c139fbea 100644 --- a/src/app/hooks/useAuthFlows.ts +++ b/src/app/hooks/useAuthFlows.ts @@ -51,6 +51,15 @@ export type AuthFlows = { authMetadata?: ValidatedAuthMetadata; }; +/** True only when the homeserver advertises the OAuth authorization-code flow Sable uses. */ +export const isUsableOAuthMetadata = (metadata: ValidatedAuthMetadata | undefined): boolean => + metadata !== undefined && + metadata.grant_types_supported.includes('authorization_code') && + metadata.grant_types_supported.includes('refresh_token') && + metadata.response_types_supported.includes('code') && + metadata.response_modes_supported.includes('fragment') && + metadata.code_challenge_methods_supported.includes('S256'); + const AuthFlowsContext = createContext(null); export const AuthFlowsProvider = AuthFlowsContext.Provider; diff --git a/src/app/pages/auth/login/Login.tsx b/src/app/pages/auth/login/Login.tsx index cdb3f91f0..f742c58d5 100644 --- a/src/app/pages/auth/login/Login.tsx +++ b/src/app/pages/auth/login/Login.tsx @@ -2,10 +2,10 @@ import { useMemo, useState } from 'react'; import { Box, Switch, Text, Tooltip, TooltipProvider, color, config } from 'folds'; import { Link, useSearchParams } from 'react-router-dom'; import { SSOAction } from '$types/matrix-sdk'; -import { RegisterFlowStatus, useAuthFlows } from '$hooks/useAuthFlows'; +import { isUsableOAuthMetadata, RegisterFlowStatus, useAuthFlows } from '$hooks/useAuthFlows'; import { useAuthServer } from '$hooks/useAuthServer'; import { useAutoDiscoveryInfo } from '$hooks/useAutoDiscoveryInfo'; -import { isOauthAwarePreferred, useParsedLoginFlows } from '$hooks/useParsedLoginFlows'; +import { useParsedLoginFlows } from '$hooks/useParsedLoginFlows'; import { getLoginPath, getRegisterPath, withSearchParam } from '$pages/pathUtils'; import { usePathWithOrigin } from '$hooks/usePathWithOrigin'; import type { LoginPathSearchParams } from '$pages/paths'; @@ -131,11 +131,10 @@ export function Login() { ? (oidcErrorDescription ?? `Sign-in was not completed (${oidcError}).`) : undefined; - const showOidc = authMetadata !== undefined; - const hidePassword = - hideUsernamePasswordFields || (showOidc && isOauthAwarePreferred(parsedFlows.sso)); + const showOidc = isUsableOAuthMetadata(authMetadata); + const hidePassword = hideUsernamePasswordFields; const showPassword = !hidePassword && parsedFlows.password !== undefined; - const showLegacySso = !showOidc && parsedFlows.sso !== undefined; + const showLegacySso = parsedFlows.sso !== undefined; if (showOidc && oidcCode && oidcState) { return ; @@ -146,26 +145,10 @@ export function Login() { Login - {!showPassword && ( - - )} + {parsedFlows.token && loginSearchParams.loginToken && ( )} - {showPassword && ( - <> - - } - /> - - {(showLegacySso || showOidc) && } - - )} {showOidc && ( <> + {showOidc && } + + + )} + {showPassword && ( + <> + {(showLegacySso || (showOidc && !showLegacySso)) && } + From 46b8018af3c118db0ceea50100a272c18d727f5d Mon Sep 17 00:00:00 2001 From: 7w1 Date: Sat, 25 Jul 2026 17:10:13 -0500 Subject: [PATCH 3/3] lint --- src/app/features/settings/devices/OtherDevices.tsx | 4 ++-- src/app/pages/auth/login/Login.tsx | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/features/settings/devices/OtherDevices.tsx b/src/app/features/settings/devices/OtherDevices.tsx index 78877a492..245ba333e 100644 --- a/src/app/features/settings/devices/OtherDevices.tsx +++ b/src/app/features/settings/devices/OtherDevices.tsx @@ -76,7 +76,7 @@ export function OtherDevices({ devices, refreshDeviceList, showVerification }: O return; } window.open(url, '_blank'); - }, [authMetadata, accountManagementActions]); + }, [authMetadata, accountManagementActions, mx]); const handleDeleteOIDC = useCallback( (deviceId: string) => { @@ -95,7 +95,7 @@ export function OtherDevices({ devices, refreshDeviceList, showVerification }: O } window.open(url, '_blank'); }, - [authMetadata, accountManagementActions] + [authMetadata, accountManagementActions, mx] ); const handleToggleDelete = useCallback((deviceId: string) => { diff --git a/src/app/pages/auth/login/Login.tsx b/src/app/pages/auth/login/Login.tsx index f742c58d5..59c7dd83b 100644 --- a/src/app/pages/auth/login/Login.tsx +++ b/src/app/pages/auth/login/Login.tsx @@ -131,7 +131,8 @@ export function Login() { ? (oidcErrorDescription ?? `Sign-in was not completed (${oidcError}).`) : undefined; - const showOidc = isUsableOAuthMetadata(authMetadata); + const oidcMetadata = isUsableOAuthMetadata(authMetadata) ? authMetadata : undefined; + const showOidc = oidcMetadata !== undefined; const hidePassword = hideUsernamePasswordFields; const showPassword = !hidePassword && parsedFlows.password !== undefined; const showLegacySso = parsedFlows.sso !== undefined; @@ -152,7 +153,7 @@ export function Login() { {showOidc && ( <>