Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix relationship between guests, .well-known, and auth #3001

Merged
merged 33 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
636cb8a
Have ServerConfig and co. do validation of the config in-house
turt2live May 3, 2019
6b45e60
Update ServerTypeSelector for registration to use a server config
turt2live May 3, 2019
00ebb5e
Make registration work with server configs
turt2live May 3, 2019
b6e027f
Make password resets use server config objects
turt2live May 3, 2019
0b1a0c7
Make login pass around server config objects
turt2live May 3, 2019
1f527e7
Bring server config juggling into MatrixChat
turt2live May 3, 2019
bb6ee10
Add language features to support server config changes
turt2live May 3, 2019
a4b6464
Appease the linter
turt2live May 3, 2019
ae63df9
Fix tests to use new serverConfig prop
turt2live May 3, 2019
4ada66d
Fix rogue instance of old hsUrl property
turt2live May 3, 2019
58b9eb4
Add a serverConfig property to MatrixChat for unit tests
turt2live May 3, 2019
eab209a
Log in to the right homeserver when changing the homeserver
turt2live May 6, 2019
6a941ac
Merge pull request #2941 from matrix-org/travis/guests/block-ui
turt2live May 10, 2019
8373765
Merge branch 'develop' into travis/feature/wellknown2
turt2live May 13, 2019
ee33a4e
Refactor "Next" button into ServerConfig components
turt2live May 13, 2019
e4576da
Render underlines and tooltips on custom server names in auth pages
turt2live May 13, 2019
25e3f78
newline for the linter
turt2live May 14, 2019
4c1ac38
Merge branch 'develop' into travis/feature/wellknown2
turt2live May 14, 2019
bb16357
Flag all generated configs as non-default by default
turt2live May 14, 2019
34719b9
Only expose the fallback_hs_url if the homeserver is the default HS
turt2live May 14, 2019
9b5830b
Restore use of full mxid login
turt2live May 14, 2019
6e3b06f
Human de-linting
turt2live May 15, 2019
60a1365
Merge pull request #2965 from matrix-org/travis/wk/tooltip
turt2live May 15, 2019
8c326bf
Merge pull request #2964 from matrix-org/travis/wk/simplify-phases
turt2live May 16, 2019
f75dc9c
Merge pull request #2971 from matrix-org/travis/wk/fallback_hs
turt2live May 16, 2019
1ea5b42
Merge branch 'travis/feature/wellknown2' into travis/wk/mxid
turt2live May 16, 2019
3e10d3c
Merge pull request #2972 from matrix-org/travis/wk/mxid
turt2live May 16, 2019
0c7aa39
Merge branch 'develop' into travis/feature/wellknown2
turt2live May 16, 2019
3476be3
Merge branch 'develop' into travis/feature/wellknown2
turt2live May 21, 2019
595b490
Don't act busy on the login page for moving your cursor
turt2live May 21, 2019
7ecab35
Add a null guard for serverConfig
turt2live May 21, 2019
14dc4b4
Merge branch 'develop' into travis/feature/wellknown2
turt2live May 23, 2019
ea1c778
Fix copyright
turt2live May 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions res/css/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
@import "./views/elements/_RoleButton.scss";
@import "./views/elements/_Spinner.scss";
@import "./views/elements/_SyntaxHighlight.scss";
@import "./views/elements/_TextWithTooltip.scss";
@import "./views/elements/_ToggleSwitch.scss";
@import "./views/elements/_ToolTipButton.scss";
@import "./views/elements/_Tooltip.scss";
Expand Down
4 changes: 4 additions & 0 deletions res/css/structures/auth/_Login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ limitations under the License.
.mx_Login_type_dropdown {
min-width: 200px;
}

.mx_Login_underlinedServerName {
border-bottom: 1px dashed $accent-color;
}
5 changes: 5 additions & 0 deletions res/css/views/auth/_ServerConfig.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ limitations under the License.
.mx_ServerConfig_help:link {
opacity: 0.8;
}

.mx_ServerConfig_error {
display: block;
color: $warning-color;
}
19 changes: 19 additions & 0 deletions res/css/views/elements/_TextWithTooltip.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright 2019 New Vector Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_TextWithTooltip_tooltip {
display: none;
}
158 changes: 21 additions & 137 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ import SettingsStore, {SettingLevel} from "../../settings/SettingsStore";
import { startAnyRegistrationFlow } from "../../Registration.js";
import { messageForSyncError } from '../../utils/ErrorUtils';
import ResizeNotifier from "../../utils/ResizeNotifier";

const AutoDiscovery = Matrix.AutoDiscovery;
import {ValidatedServerConfig} from "../../utils/AutoDiscoveryUtils";

// Disable warnings for now: we use deprecated bluebird functions
// and need to migrate, but they spam the console with warnings.
Expand Down Expand Up @@ -109,6 +108,7 @@ export default React.createClass({

propTypes: {
config: PropTypes.object,
serverConfig: PropTypes.instanceOf(ValidatedServerConfig),
ConferenceHandler: PropTypes.any,
onNewScreen: PropTypes.func,
registrationUrl: PropTypes.string,
Expand Down Expand Up @@ -181,16 +181,8 @@ export default React.createClass({
// Parameters used in the registration dance with the IS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested the email validation flow with these changes in place? (That's one area we've tended to break...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, several times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to follow up: I re-tested the two common scenarios just to be absolutely sure it works.

register_client_secret: null,
register_session_id: null,
register_hs_url: null,
register_is_url: null,
register_id_sid: null,

// Parameters used for setting up the authentication views
defaultServerName: this.props.config.default_server_name,
defaultHsUrl: this.props.config.default_hs_url,
defaultIsUrl: this.props.config.default_is_url,
defaultServerDiscoveryError: null,

// When showing Modal dialogs we need to set aria-hidden on the root app element
// and disable it when there are no dialogs
hideToSRUsers: false,
Expand All @@ -211,42 +203,19 @@ export default React.createClass({
};
},

getDefaultServerName: function() {
return this.state.defaultServerName;
},

getCurrentHsUrl: function() {
if (this.state.register_hs_url) {
return this.state.register_hs_url;
} else if (MatrixClientPeg.get()) {
return MatrixClientPeg.get().getHomeserverUrl();
} else {
return this.getDefaultHsUrl();
}
},

getDefaultHsUrl(defaultToMatrixDotOrg) {
defaultToMatrixDotOrg = typeof(defaultToMatrixDotOrg) !== 'boolean' ? true : defaultToMatrixDotOrg;
if (!this.state.defaultHsUrl && defaultToMatrixDotOrg) return "https://matrix.org";
return this.state.defaultHsUrl;
},

getFallbackHsUrl: function() {
return this.props.config.fallback_hs_url;
},

getCurrentIsUrl: function() {
if (this.state.register_is_url) {
return this.state.register_is_url;
} else if (MatrixClientPeg.get()) {
return MatrixClientPeg.get().getIdentityServerUrl();
if (this.props.serverConfig && this.props.serverConfig.isDefault) {
return this.props.config.fallback_hs_url;
} else {
return this.getDefaultIsUrl();
return null;
}
},

getDefaultIsUrl() {
return this.state.defaultIsUrl || "https://vector.im";
getServerProperties() {
let props = this.state.serverConfig;
if (!props) props = this.props.serverConfig; // for unit tests
if (!props) props = SdkConfig.get()["validated_server_config"];
return {serverConfig: props};
},

componentWillMount: function() {
Expand All @@ -260,40 +229,6 @@ export default React.createClass({
MatrixClientPeg.opts.initialSyncLimit = this.props.config.sync_timeline_limit;
}

// Set up the default URLs (async)
if (this.getDefaultServerName() && !this.getDefaultHsUrl(false)) {
this.setState({loadingDefaultHomeserver: true});
this._tryDiscoverDefaultHomeserver(this.getDefaultServerName());
} else if (this.getDefaultServerName() && this.getDefaultHsUrl(false)) {
// Ideally we would somehow only communicate this to the server admins, but
// given this is at login time we can't really do much besides hope that people
// will check their settings.
this.setState({
defaultServerName: null, // To un-hide any secrets people might be keeping
defaultServerDiscoveryError: _t(
"Invalid configuration: Cannot supply a default homeserver URL and " +
"a default server name",
),
});
}

// Set a default HS with query param `hs_url`
const paramHs = this.props.startingFragmentQueryParams.hs_url;
if (paramHs) {
console.log('Setting register_hs_url ', paramHs);
this.setState({
register_hs_url: paramHs,
});
}
// Set a default IS with query param `is_url`
const paramIs = this.props.startingFragmentQueryParams.is_url;
if (paramIs) {
console.log('Setting register_is_url ', paramIs);
this.setState({
register_is_url: paramIs,
});
}

// a thing to call showScreen with once login completes. this is kept
// outside this.state because updating it should never trigger a
// rerender.
Expand Down Expand Up @@ -374,8 +309,8 @@ export default React.createClass({
return Lifecycle.loadSession({
fragmentQueryParams: this.props.startingFragmentQueryParams,
enableGuest: this.props.enableGuest,
guestHsUrl: this.getCurrentHsUrl(),
guestIsUrl: this.getCurrentIsUrl(),
guestHsUrl: this.getServerProperties().serverConfig.hsUrl,
guestIsUrl: this.getServerProperties().serverConfig.isUrl,
defaultDeviceDisplayName: this.props.defaultDeviceDisplayName,
});
}).then((loadedSession) => {
Expand Down Expand Up @@ -1827,44 +1762,7 @@ export default React.createClass({
},

onServerConfigChange(config) {
const newState = {};
if (config.hsUrl) {
newState.register_hs_url = config.hsUrl;
}
if (config.isUrl) {
newState.register_is_url = config.isUrl;
}
this.setState(newState);
},

_tryDiscoverDefaultHomeserver: async function(serverName) {
try {
const discovery = await AutoDiscovery.findClientConfig(serverName);
const state = discovery["m.homeserver"].state;
if (state !== AutoDiscovery.SUCCESS) {
console.error("Failed to discover homeserver on startup:", discovery);
this.setState({
defaultServerDiscoveryError: discovery["m.homeserver"].error,
loadingDefaultHomeserver: false,
});
} else {
const hsUrl = discovery["m.homeserver"].base_url;
const isUrl = discovery["m.identity_server"].state === AutoDiscovery.SUCCESS
? discovery["m.identity_server"].base_url
: "https://vector.im";
this.setState({
defaultHsUrl: hsUrl,
defaultIsUrl: isUrl,
loadingDefaultHomeserver: false,
});
}
} catch (e) {
console.error(e);
this.setState({
defaultServerDiscoveryError: _t("Unknown error discovering homeserver"),
loadingDefaultHomeserver: false,
});
}
this.setState({serverConfig: config});
},

_makeRegistrationUrl: function(params) {
Expand All @@ -1883,8 +1781,7 @@ export default React.createClass({

if (
this.state.view === VIEWS.LOADING ||
this.state.view === VIEWS.LOGGING_IN ||
this.state.loadingDefaultHomeserver
this.state.view === VIEWS.LOGGING_IN
) {
const Spinner = sdk.getComponent('elements.Spinner');
return (
Expand Down Expand Up @@ -1962,18 +1859,13 @@ export default React.createClass({
sessionId={this.state.register_session_id}
idSid={this.state.register_id_sid}
email={this.props.startingFragmentQueryParams.email}
defaultServerName={this.getDefaultServerName()}
defaultServerDiscoveryError={this.state.defaultServerDiscoveryError}
defaultHsUrl={this.getDefaultHsUrl()}
defaultIsUrl={this.getDefaultIsUrl()}
brand={this.props.config.brand}
customHsUrl={this.getCurrentHsUrl()}
customIsUrl={this.getCurrentIsUrl()}
makeRegistrationUrl={this._makeRegistrationUrl}
onLoggedIn={this.onRegistered}
onLoginClick={this.onLoginClick}
onServerConfigChange={this.onServerConfigChange}
/>
{...this.getServerProperties()}
/>
);
}

Expand All @@ -1982,14 +1874,11 @@ export default React.createClass({
const ForgotPassword = sdk.getComponent('structures.auth.ForgotPassword');
return (
<ForgotPassword
defaultServerName={this.getDefaultServerName()}
defaultServerDiscoveryError={this.state.defaultServerDiscoveryError}
defaultHsUrl={this.getDefaultHsUrl()}
defaultIsUrl={this.getDefaultIsUrl()}
customHsUrl={this.getCurrentHsUrl()}
customIsUrl={this.getCurrentIsUrl()}
onComplete={this.onLoginClick}
onLoginClick={this.onLoginClick} />
onLoginClick={this.onLoginClick}
onServerConfigChange={this.onServerConfigChange}
{...this.getServerProperties()}
/>
);
}

Expand All @@ -1999,16 +1888,11 @@ export default React.createClass({
<Login
onLoggedIn={Lifecycle.setLoggedIn}
onRegisterClick={this.onRegisterClick}
defaultServerName={this.getDefaultServerName()}
defaultServerDiscoveryError={this.state.defaultServerDiscoveryError}
defaultHsUrl={this.getDefaultHsUrl()}
defaultIsUrl={this.getDefaultIsUrl()}
customHsUrl={this.getCurrentHsUrl()}
customIsUrl={this.getCurrentIsUrl()}
fallbackHsUrl={this.getFallbackHsUrl()}
defaultDeviceDisplayName={this.props.defaultDeviceDisplayName}
onForgotPasswordClick={this.onForgotPasswordClick}
onServerConfigChange={this.onServerConfigChange}
{...this.getServerProperties()}
/>
);
}
Expand Down
Loading