mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 17:11:17 -08:00
fix: ensure correct url for acccount management
This commit is contained in:
1 parent
4edda08cac
commit
787d1e1aaf
4 files changed
+48
-5
No files matched your search
@@ -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()) {
|
||||
|
||||
@@ -257,6 +257,7 @@ export function EnableVerification({ visible }: EnableVerificationProps) {
|
||||
export function DeviceVerificationOptions() {
|
||||
const [menuCords, setMenuCords] = useState<RectCords>();
|
||||
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')
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user