Remove backwards compatibility in ServerConfig for m.require_identity_server

This commit is contained in:
Michael Telatynski 2020-11-24 15:58:34 +00:00
parent f7d7182dc9
commit 2f64160a0e
7 changed files with 3 additions and 170 deletions

View file

@ -23,13 +23,3 @@ limitations under the License.
display: block; display: block;
color: $warning-color; color: $warning-color;
} }
.mx_ServerConfig_identityServer {
transform: scaleY(0);
transform-origin: top;
transition: transform 0.25s;
&.mx_ServerConfig_identityServer_shown {
transform: scaleY(1);
}
}

View file

@ -40,10 +40,6 @@ export default class PasswordReset {
this.identityServerDomain = identityUrl ? identityUrl.split("://")[1] : null; this.identityServerDomain = identityUrl ? identityUrl.split("://")[1] : null;
} }
doesServerRequireIdServerParam() {
return this.client.doesServerRequireIdServerParam();
}
/** /**
* Attempt to reset the user's password. This will trigger a side-effect of * Attempt to reset the user's password. This will trigger a side-effect of
* sending an email to the provided email address. * sending an email to the provided email address.
@ -78,9 +74,6 @@ export default class PasswordReset {
sid: this.sessionId, sid: this.sessionId,
client_secret: this.clientSecret, client_secret: this.clientSecret,
}; };
if (await this.doesServerRequireIdServerParam()) {
creds.id_server = this.identityServerDomain;
}
try { try {
await this.client.setPassword({ await this.client.setPassword({

View file

@ -62,7 +62,6 @@ export default class ForgotPassword extends React.Component {
serverIsAlive: true, serverIsAlive: true,
serverErrorIsFatal: false, serverErrorIsFatal: false,
serverDeadError: "", serverDeadError: "",
serverRequiresIdServer: null,
}; };
constructor(props) { constructor(props) {
@ -93,12 +92,8 @@ export default class ForgotPassword extends React.Component {
serverConfig.isUrl, serverConfig.isUrl,
); );
const pwReset = new PasswordReset(serverConfig.hsUrl, serverConfig.isUrl);
const serverRequiresIdServer = await pwReset.doesServerRequireIdServerParam();
this.setState({ this.setState({
serverIsAlive: true, serverIsAlive: true,
serverRequiresIdServer,
}); });
} catch (e) { } catch (e) {
this.setState(AutoDiscoveryUtils.authComponentStateForError(e, "forgot_password")); this.setState(AutoDiscoveryUtils.authComponentStateForError(e, "forgot_password"));
@ -216,7 +211,6 @@ export default class ForgotPassword extends React.Component {
serverConfig={this.props.serverConfig} serverConfig={this.props.serverConfig}
onServerConfigChange={this.props.onServerConfigChange} onServerConfigChange={this.props.onServerConfigChange}
delayTimeMs={0} delayTimeMs={0}
showIdentityServerIfRequiredByHomeserver={true}
onAfterSubmit={this.onServerDetailsNextPhaseClick} onAfterSubmit={this.onServerDetailsNextPhaseClick}
submitText={_t("Next")} submitText={_t("Next")}
submitClass="mx_Login_submit" submitClass="mx_Login_submit"
@ -274,22 +268,6 @@ export default class ForgotPassword extends React.Component {
</a>; </a>;
} }
if (!this.props.serverConfig.isUrl && this.state.serverRequiresIdServer) {
return <div>
<h3>
{yourMatrixAccountText}
{editLink}
</h3>
{_t(
"No identity server is configured: " +
"add one in server settings to reset your password.",
)}
<a className="mx_AuthBody_changeFlow" onClick={this.onLoginClick} href="#">
{_t('Sign in instead')}
</a>
</div>;
}
return <div> return <div>
{errorText} {errorText}
{serverDeadSection} {serverDeadSection}

View file

@ -111,8 +111,6 @@ interface IState {
// Our matrix client - part of state because we can't render the UI auth // Our matrix client - part of state because we can't render the UI auth
// component without it. // component without it.
matrixClient?: MatrixClient; matrixClient?: MatrixClient;
// whether the HS requires an ID server to register with a threepid
serverRequiresIdServer?: boolean;
// The user ID we've just registered // The user ID we've just registered
registeredUsername?: string; registeredUsername?: string;
// if a different user ID to the one we just registered is logged in, // if a different user ID to the one we just registered is logged in,
@ -254,13 +252,6 @@ export default class Registration extends React.Component<IProps, IState> {
idBaseUrl: isUrl, idBaseUrl: isUrl,
}); });
let serverRequiresIdServer = true;
try {
serverRequiresIdServer = await cli.doesServerRequireIdServerParam();
} catch (e) {
console.log("Unable to determine is server needs id_server param", e);
}
this.loginLogic.setHomeserverUrl(hsUrl); this.loginLogic.setHomeserverUrl(hsUrl);
this.loginLogic.setIdentityServerUrl(isUrl); this.loginLogic.setIdentityServerUrl(isUrl);
@ -274,7 +265,6 @@ export default class Registration extends React.Component<IProps, IState> {
this.setState({ this.setState({
matrixClient: cli, matrixClient: cli,
serverRequiresIdServer,
ssoFlow, ssoFlow,
busy: false, busy: false,
}); });
@ -573,7 +563,6 @@ export default class Registration extends React.Component<IProps, IState> {
serverConfig={this.props.serverConfig} serverConfig={this.props.serverConfig}
onServerConfigChange={this.props.onServerConfigChange} onServerConfigChange={this.props.onServerConfigChange}
delayTimeMs={250} delayTimeMs={250}
showIdentityServerIfRequiredByHomeserver={true}
onAfterSubmit={this.onServerDetailsNextPhaseClick} onAfterSubmit={this.onServerDetailsNextPhaseClick}
submitText={_t("Next")} submitText={_t("Next")}
submitClass="mx_Login_submit" submitClass="mx_Login_submit"
@ -644,7 +633,6 @@ export default class Registration extends React.Component<IProps, IState> {
flows={this.state.flows} flows={this.state.flows}
serverConfig={this.props.serverConfig} serverConfig={this.props.serverConfig}
canSubmit={!this.state.serverErrorIsFatal} canSubmit={!this.state.serverErrorIsFatal}
serverRequiresIdServer={this.state.serverRequiresIdServer}
/> />
</React.Fragment>; </React.Fragment>;
} }

View file

@ -18,7 +18,6 @@ limitations under the License.
import React, {createRef} from 'react'; import React, {createRef} from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import url from 'url';
import classnames from 'classnames'; import classnames from 'classnames';
import * as sdk from '../../../index'; import * as sdk from '../../../index';
@ -500,17 +499,11 @@ export class MsisdnAuthEntry extends React.Component {
}); });
try { try {
const requiresIdServerParam =
await this.props.matrixClient.doesServerRequireIdServerParam();
let result; let result;
if (this._submitUrl) { if (this._submitUrl) {
result = await this.props.matrixClient.submitMsisdnTokenOtherUrl( result = await this.props.matrixClient.submitMsisdnTokenOtherUrl(
this._submitUrl, this._sid, this.props.clientSecret, this.state.token, this._submitUrl, this._sid, this.props.clientSecret, this.state.token,
); );
} else if (requiresIdServerParam) {
result = await this.props.matrixClient.submitMsisdnToken(
this._sid, this.props.clientSecret, this.state.token,
);
} else { } else {
throw new Error("The registration with MSISDN flow is misconfigured"); throw new Error("The registration with MSISDN flow is misconfigured");
} }
@ -519,12 +512,6 @@ export class MsisdnAuthEntry extends React.Component {
sid: this._sid, sid: this._sid,
client_secret: this.props.clientSecret, client_secret: this.props.clientSecret,
}; };
if (requiresIdServerParam) {
const idServerParsedUrl = url.parse(
this.props.matrixClient.getIdentityServerUrl(),
);
creds.id_server = idServerParsedUrl.host;
}
this.props.submitAuthDict({ this.props.submitAuthDict({
type: MsisdnAuthEntry.LOGIN_TYPE, type: MsisdnAuthEntry.LOGIN_TYPE,
// TODO: Remove `threepid_creds` once servers support proper UIA // TODO: Remove `threepid_creds` once servers support proper UIA

View file

@ -54,7 +54,6 @@ interface IProps {
}[]; }[];
serverConfig: ValidatedServerConfig; serverConfig: ValidatedServerConfig;
canSubmit?: boolean; canSubmit?: boolean;
serverRequiresIdServer?: boolean;
onRegisterClick(params: { onRegisterClick(params: {
username: string; username: string;
@ -118,21 +117,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
} }
if (this.state.email === '') { if (this.state.email === '') {
const haveIs = Boolean(this.props.serverConfig.isUrl); if (this.showEmail()) {
if (this.props.serverRequiresIdServer && !haveIs) {
Modal.createTrackedDialog("No identity server no email", '', QuestionDialog, {
title: _t("Warning!"),
description: _t(
"No identity server is configured so you cannot add an email address in order to " +
"reset your password in the future.",
),
button: _t("Continue"),
onFinished: async (confirmed) => {
if (confirmed) this.doSubmit(ev);
},
});
} else if (this.showEmail()) {
CountlyAnalytics.instance.track("onboarding_registration_submit_warn"); CountlyAnalytics.instance.track("onboarding_registration_submit_warn");
Modal.createTrackedDialog("Email prompt dialog", '', RegistrationEmailPromptDialog, { Modal.createTrackedDialog("Email prompt dialog", '', RegistrationEmailPromptDialog, {
onFinished: async (confirmed: boolean, email?: string) => { onFinished: async (confirmed: boolean, email?: string) => {
@ -420,11 +405,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
} }
private showEmail() { private showEmail() {
const haveIs = Boolean(this.props.serverConfig.isUrl); if (!this.authStepIsUsed('m.login.email.identity')) {
if (
(this.props.serverRequiresIdServer && !haveIs) ||
!this.authStepIsUsed('m.login.email.identity')
) {
return false; return false;
} }
return true; return true;
@ -432,12 +413,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
private showPhoneNumber() { private showPhoneNumber() {
const threePidLogin = !SdkConfig.get().disable_3pid_login; const threePidLogin = !SdkConfig.get().disable_3pid_login;
const haveIs = Boolean(this.props.serverConfig.isUrl); if (!threePidLogin || !this.authStepIsUsed('m.login.msisdn')) {
if (
!threePidLogin ||
(this.props.serverRequiresIdServer && !haveIs) ||
!this.authStepIsUsed('m.login.msisdn')
) {
return false; return false;
} }
return true; return true;
@ -556,16 +532,6 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
</div>; </div>;
} }
} }
const haveIs = Boolean(this.props.serverConfig.isUrl);
let noIsText = null;
if (this.props.serverRequiresIdServer && !haveIs) {
noIsText = <div>
{_t(
"No identity server is configured so you cannot add an email address in order to " +
"reset your password in the future.",
)}
</div>;
}
return ( return (
<div> <div>
@ -582,7 +548,6 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
{this.renderPhoneNumber()} {this.renderPhoneNumber()}
</div> </div>
{ emailHelperText } { emailHelperText }
{ noIsText }
{ registerButton } { registerButton }
</form> </form>
</div> </div>

View file

@ -24,8 +24,6 @@ import { _t } from '../../../languageHandler';
import {ValidatedServerConfig} from "../../../utils/AutoDiscoveryUtils"; import {ValidatedServerConfig} from "../../../utils/AutoDiscoveryUtils";
import AutoDiscoveryUtils from "../../../utils/AutoDiscoveryUtils"; import AutoDiscoveryUtils from "../../../utils/AutoDiscoveryUtils";
import SdkConfig from "../../../SdkConfig"; import SdkConfig from "../../../SdkConfig";
import { createClient } from 'matrix-js-sdk/src/matrix';
import classNames from 'classnames';
import CountlyAnalytics from "../../../CountlyAnalytics"; import CountlyAnalytics from "../../../CountlyAnalytics";
/* /*
@ -50,10 +48,6 @@ export default class ServerConfig extends React.PureComponent {
// Optional class for the submit button. Only applies if the submit button // Optional class for the submit button. Only applies if the submit button
// is to be rendered. // is to be rendered.
submitClass: PropTypes.string, submitClass: PropTypes.string,
// Whether the flow this component is embedded in requires an identity
// server when the homeserver says it will need one. Default false.
showIdentityServerIfRequiredByHomeserver: PropTypes.bool,
}; };
static defaultProps = { static defaultProps = {
@ -69,7 +63,6 @@ export default class ServerConfig extends React.PureComponent {
errorText: "", errorText: "",
hsUrl: props.serverConfig.hsUrl, hsUrl: props.serverConfig.hsUrl,
isUrl: props.serverConfig.isUrl, isUrl: props.serverConfig.isUrl,
showIdentityServer: false,
}; };
CountlyAnalytics.instance.track("onboarding_custom_server"); CountlyAnalytics.instance.track("onboarding_custom_server");
@ -92,23 +85,6 @@ export default class ServerConfig extends React.PureComponent {
return result; return result;
} }
// If the UI flow this component is embedded in requires an identity
// server when the homeserver says it will need one, check first and
// reveal this field if not already shown.
// XXX: This a backward compatibility path for homeservers that require
// an identity server to be passed during certain flows.
// See also https://github.com/matrix-org/synapse/pull/5868.
if (
this.props.showIdentityServerIfRequiredByHomeserver &&
!this.state.showIdentityServer &&
await this.isIdentityServerRequiredByHomeserver()
) {
this.setState({
showIdentityServer: true,
});
return null;
}
return result; return result;
} }
@ -165,15 +141,6 @@ export default class ServerConfig extends React.PureComponent {
} }
} }
async isIdentityServerRequiredByHomeserver() {
// XXX: We shouldn't have to create a whole new MatrixClient just to
// check if the homeserver requires an identity server... Should it be
// extracted to a static utils function...?
return createClient({
baseUrl: this.state.hsUrl,
}).doesServerRequireIdServerParam();
}
onHomeserverBlur = (ev) => { onHomeserverBlur = (ev) => {
this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, () => { this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, () => {
this.validateServer(); this.validateServer();
@ -185,17 +152,6 @@ export default class ServerConfig extends React.PureComponent {
this.setState({ hsUrl }); this.setState({ hsUrl });
}; };
onIdentityServerBlur = (ev) => {
this._isTimeoutId = this._waitThenInvoke(this._isTimeoutId, () => {
this.validateServer();
});
};
onIdentityServerChange = (ev) => {
const isUrl = ev.target.value;
this.setState({ isUrl });
};
onSubmit = async (ev) => { onSubmit = async (ev) => {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
@ -239,29 +195,6 @@ export default class ServerConfig extends React.PureComponent {
</div>; </div>;
} }
_renderIdentityServerSection() {
const Field = sdk.getComponent('elements.Field');
const classes = classNames({
"mx_ServerConfig_identityServer": true,
"mx_ServerConfig_identityServer_shown": this.state.showIdentityServer,
});
return <div className={classes}>
{_t("Enter your custom identity server URL <a>What does this mean?</a>", {}, {
a: sub => <a className="mx_ServerConfig_help" href="#" onClick={this.showHelpPopup}>
{sub}
</a>,
})}
<Field
label={_t("Identity Server URL")}
placeholder={this.props.serverConfig.isUrl}
value={this.state.isUrl || ''}
onBlur={this.onIdentityServerBlur}
onChange={this.onIdentityServerChange}
disabled={this.state.busy}
/>
</div>;
}
render() { render() {
const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
@ -283,7 +216,6 @@ export default class ServerConfig extends React.PureComponent {
<h3>{_t("Other servers")}</h3> <h3>{_t("Other servers")}</h3>
{errorText} {errorText}
{this._renderHomeserverSection()} {this._renderHomeserverSection()}
{this._renderIdentityServerSection()}
{submitButton} {submitButton}
</form> </form>
); );