From f05a11db42afb6c8813ee22dcf6a9af4ff4e8154 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Sat, 25 Jul 2026 16:56:57 -0500 Subject: [PATCH] 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)) && } +