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
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
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import { createContext, useContext } from 'react';
|
|
import { IAuthData, MatrixError, ValidatedAuthMetadata } from 'matrix-js-sdk';
|
|
import { ILoginFlowsResponse } from 'matrix-js-sdk/lib/@types/auth';
|
|
|
|
export enum RegisterFlowStatus {
|
|
FlowRequired = 401,
|
|
InvalidRequest = 400,
|
|
RegistrationDisabled = 403,
|
|
RateLimited = 429,
|
|
}
|
|
|
|
export type RegisterFlowsResponse =
|
|
| {
|
|
status: RegisterFlowStatus.FlowRequired;
|
|
data: IAuthData;
|
|
}
|
|
| {
|
|
status: Exclude<RegisterFlowStatus, RegisterFlowStatus.FlowRequired>;
|
|
};
|
|
|
|
export const parseRegisterErrResp = (matrixError: MatrixError): RegisterFlowsResponse => {
|
|
switch (matrixError.httpStatus) {
|
|
case RegisterFlowStatus.InvalidRequest: {
|
|
return { status: RegisterFlowStatus.InvalidRequest };
|
|
}
|
|
case RegisterFlowStatus.RateLimited: {
|
|
return { status: RegisterFlowStatus.RateLimited };
|
|
}
|
|
case RegisterFlowStatus.RegistrationDisabled: {
|
|
return { status: RegisterFlowStatus.RegistrationDisabled };
|
|
}
|
|
case RegisterFlowStatus.FlowRequired: {
|
|
return {
|
|
status: RegisterFlowStatus.FlowRequired,
|
|
data: matrixError.data as IAuthData,
|
|
};
|
|
}
|
|
default: {
|
|
return { status: RegisterFlowStatus.InvalidRequest };
|
|
}
|
|
}
|
|
};
|
|
|
|
export type AuthFlows = {
|
|
loginFlows: ILoginFlowsResponse;
|
|
registerFlows: RegisterFlowsResponse;
|
|
/**
|
|
* The homeserver's OAuth 2.0 metadata (`/_matrix/client/v1/auth_metadata`),
|
|
* when it uses native OAuth (MSC3861, e.g. matrix.org via MAS). The same
|
|
* source the SDK uses to refresh tokens, so sign-in is only offered when
|
|
* refresh will work too.
|
|
*/
|
|
authMetadata?: ValidatedAuthMetadata;
|
|
};
|
|
|
|
const AuthFlowsContext = createContext<AuthFlows | null>(null);
|
|
|
|
export const AuthFlowsProvider = AuthFlowsContext.Provider;
|
|
|
|
export const useAuthFlows = (): AuthFlows => {
|
|
const authFlows = useContext(AuthFlowsContext);
|
|
if (!authFlows) {
|
|
throw new Error('Auth Flow info is not loaded!');
|
|
}
|
|
return authFlows;
|
|
};
|