Files
cinny/src/app/pages/auth/register/Register.tsx
T
Lotus CIandClaude Opus 5.5 3c3bb2e41c
CI / Build & Quality Checks (push) Skipped
CI / Secret scan (gitleaks) (push) Skipped
CI / Playwright smoke (e2e) (push) Skipped
CI / Build & Quality Checks (pull_request) Successful in 3m41s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 10s
CI / Playwright smoke (e2e) (pull_request) Successful in 16m45s
feat(auth): offer native OAuth sign-in on servers like matrix.org
The login page looked for an OAuth issuer in .well-known
(m.authentication), which matrix.org no longer publishes, so its users
got the password / SSO compatibility forms. Detect native OAuth the way
the SDK finds the auth server for refresh: load /auth_metadata next to
the login flows. When present:
- Login shows "Continue with <server>" only (as Element does); a legacy
  SSO loginToken coming back from a redirect still completes.
- Register opens the auth server's sign-up page (prompt=create, where
  prompt_values_supported says so) instead of the legacy forms.
Servers without it (Lotus) are unchanged.

Checked against the live servers: matrix.org login and register show
"Continue with matrix.org" and no password form; matrix.lotusguild.org
keeps its password form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
2026-10-24 16:15:24 -04:00

123 lines
4.6 KiB
TypeScript

import React, { useMemo } from 'react';
import { Box, Text, color } from 'folds';
import { Link, useSearchParams } from 'react-router-dom';
import { SSOAction } from 'matrix-js-sdk';
import { useAuthServer } from '../../../hooks/useAuthServer';
import { RegisterFlowStatus, useAuthFlows } from '../../../hooks/useAuthFlows';
import { useParsedLoginFlows } from '../../../hooks/useParsedLoginFlows';
import { PasswordRegisterForm, SUPPORTED_REGISTER_STAGES } from '../register/PasswordRegisterForm';
import { OrDivider } from '../OrDivider';
import { SSOLogin } from '../SSOLogin';
import { SupportedUIAFlowsLoader } from '../../../components/SupportedUIAFlowsLoader';
import { getLoginPath } from '../../pathUtils';
import { usePathWithOrigin } from '../../../hooks/usePathWithOrigin';
import { RegisterPathSearchParams } from '../../paths';
import { useAutoDiscoveryInfo } from '../../../hooks/useAutoDiscoveryInfo';
import { OidcLogin } from '../login/OidcLogin';
const useRegisterSearchParams = (searchParams: URLSearchParams): RegisterPathSearchParams =>
useMemo(
() => ({
username: searchParams.get('username') ?? undefined,
email: searchParams.get('email') ?? undefined,
token: searchParams.get('token') ?? undefined,
}),
[searchParams],
);
export function Register() {
const server = useAuthServer();
const { loginFlows, registerFlows, authMetadata } = useAuthFlows();
const discovery = useAutoDiscoveryInfo();
const [searchParams] = useSearchParams();
const registerSearchParams = useRegisterSearchParams(searchParams);
const { sso } = useParsedLoginFlows(loginFlows.flows);
// redirect to /login because only that path handle m.login.token
const ssoRedirectUrl = usePathWithOrigin(getLoginPath(server));
// Native OAuth servers (e.g. matrix.org via MAS) create accounts at the auth
// server; /register here would only offer the legacy forms. Mirrors Login.
if (authMetadata) {
return (
<Box direction="Column" gap="500">
<Text as="h2" size="H2" priority="400">
Register
</Text>
<OidcLogin
register
homeserverBaseUrl={discovery['m.homeserver'].base_url}
serverName={server}
/>
<span data-spacing-node />
<Text align="Center">
Already have an account? <Link to={getLoginPath(server)}>Login</Link>
</Text>
</Box>
);
}
return (
<Box direction="Column" gap="500">
<Text as="h2" size="H2" priority="400">
Register
</Text>
{registerFlows.status === RegisterFlowStatus.RegistrationDisabled && !sso && (
<Text style={{ color: color.Critical.Main }} size="T300">
Registration has been disabled on this homeserver.
</Text>
)}
{registerFlows.status === RegisterFlowStatus.RateLimited && !sso && (
<Text style={{ color: color.Critical.Main }} size="T300">
You have been rate-limited! Please try after some time.
</Text>
)}
{registerFlows.status === RegisterFlowStatus.InvalidRequest && !sso && (
<Text style={{ color: color.Critical.Main }} size="T300">
Invalid Request! Failed to get any registration options.
</Text>
)}
{registerFlows.status === RegisterFlowStatus.FlowRequired && (
<>
<SupportedUIAFlowsLoader
flows={registerFlows.data.flows ?? []}
supportedStages={SUPPORTED_REGISTER_STAGES}
>
{(supportedFlows) =>
supportedFlows.length === 0 ? (
<Text style={{ color: color.Critical.Main }} size="T300">
This application does not support registration on this homeserver.
</Text>
) : (
<PasswordRegisterForm
authData={registerFlows.data}
uiaFlows={supportedFlows}
defaultUsername={registerSearchParams.username}
defaultEmail={registerSearchParams.email}
defaultRegisterToken={registerSearchParams.token}
/>
)
}
</SupportedUIAFlowsLoader>
<span data-spacing-node />
{sso && <OrDivider />}
</>
)}
{sso && (
<>
<SSOLogin
providers={sso.identity_providers}
redirectUrl={ssoRedirectUrl}
action={SSOAction.REGISTER}
saveScreenSpace={registerFlows.status === RegisterFlowStatus.FlowRequired}
/>
<span data-spacing-node />
</>
)}
<Text align="Center">
Already have an account? <Link to={getLoginPath(server)}>Login</Link>
</Text>
</Box>
);
}