mirror of https://github.com/vector-im/riot-web
Merge pull request #2547 from jryans/auth-well-known-state
Ensure correct server URLs with .well-known and server typepull/21833/head
commit
fb39ba1ffc
|
@ -88,8 +88,8 @@ module.exports = React.createClass({
|
||||||
loginIncorrect: false,
|
loginIncorrect: false,
|
||||||
|
|
||||||
serverType: null,
|
serverType: null,
|
||||||
enteredHomeserverUrl: this.props.customHsUrl || this.props.defaultHsUrl,
|
enteredHsUrl: this.props.customHsUrl || this.props.defaultHsUrl,
|
||||||
enteredIdentityServerUrl: this.props.customIsUrl || this.props.defaultIsUrl,
|
enteredIsUrl: this.props.customIsUrl || this.props.defaultIsUrl,
|
||||||
|
|
||||||
// used for preserving form values when changing homeserver
|
// used for preserving form values when changing homeserver
|
||||||
username: "",
|
username: "",
|
||||||
|
@ -102,8 +102,6 @@ module.exports = React.createClass({
|
||||||
currentFlow: "m.login.password",
|
currentFlow: "m.login.password",
|
||||||
|
|
||||||
// .well-known discovery
|
// .well-known discovery
|
||||||
discoveredHsUrl: "",
|
|
||||||
discoveredIsUrl: "",
|
|
||||||
discoveryError: "",
|
discoveryError: "",
|
||||||
findingHomeserver: false,
|
findingHomeserver: false,
|
||||||
};
|
};
|
||||||
|
@ -265,6 +263,11 @@ module.exports = React.createClass({
|
||||||
username: username,
|
username: username,
|
||||||
discoveryError: null,
|
discoveryError: null,
|
||||||
});
|
});
|
||||||
|
// If the free server type is selected, we don't show server details at all,
|
||||||
|
// so it doesn't make sense to try .well-known discovery.
|
||||||
|
if (this.state.serverType === ServerType.FREE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (username[0] === "@") {
|
if (username[0] === "@") {
|
||||||
const serverName = username.split(':').slice(1).join(':');
|
const serverName = username.split(':').slice(1).join(':');
|
||||||
try {
|
try {
|
||||||
|
@ -308,10 +311,10 @@ module.exports = React.createClass({
|
||||||
errorText: null, // reset err messages
|
errorText: null, // reset err messages
|
||||||
};
|
};
|
||||||
if (config.hsUrl !== undefined) {
|
if (config.hsUrl !== undefined) {
|
||||||
newState.enteredHomeserverUrl = config.hsUrl;
|
newState.enteredHsUrl = config.hsUrl;
|
||||||
}
|
}
|
||||||
if (config.isUrl !== undefined) {
|
if (config.isUrl !== undefined) {
|
||||||
newState.enteredIdentityServerUrl = config.isUrl;
|
newState.enteredIsUrl = config.isUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.onServerConfigChange(config);
|
this.props.onServerConfigChange(config);
|
||||||
|
@ -377,43 +380,50 @@ module.exports = React.createClass({
|
||||||
_tryWellKnownDiscovery: async function(serverName) {
|
_tryWellKnownDiscovery: async function(serverName) {
|
||||||
if (!serverName.trim()) {
|
if (!serverName.trim()) {
|
||||||
// Nothing to discover
|
// Nothing to discover
|
||||||
this.setState({discoveryError: "", discoveredHsUrl: "", discoveredIsUrl: "", findingHomeserver: false});
|
this.setState({
|
||||||
|
discoveryError: "",
|
||||||
|
findingHomeserver: false,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({findingHomeserver: true});
|
this.setState({findingHomeserver: true});
|
||||||
try {
|
try {
|
||||||
const discovery = await AutoDiscovery.findClientConfig(serverName);
|
const discovery = await AutoDiscovery.findClientConfig(serverName);
|
||||||
|
|
||||||
|
// The server type may have changed while discovery began in the background.
|
||||||
|
// If it has become the free server type which doesn't show server details,
|
||||||
|
// ignore discovery results.
|
||||||
|
if (this.state.serverType === ServerType.FREE) {
|
||||||
|
this.setState({findingHomeserver: false});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const state = discovery["m.homeserver"].state;
|
const state = discovery["m.homeserver"].state;
|
||||||
if (state !== AutoDiscovery.SUCCESS && state !== AutoDiscovery.PROMPT) {
|
if (state !== AutoDiscovery.SUCCESS && state !== AutoDiscovery.PROMPT) {
|
||||||
this.setState({
|
this.setState({
|
||||||
discoveredHsUrl: "",
|
|
||||||
discoveredIsUrl: "",
|
|
||||||
discoveryError: discovery["m.homeserver"].error,
|
discoveryError: discovery["m.homeserver"].error,
|
||||||
findingHomeserver: false,
|
findingHomeserver: false,
|
||||||
});
|
});
|
||||||
} else if (state === AutoDiscovery.PROMPT) {
|
} else if (state === AutoDiscovery.PROMPT) {
|
||||||
this.setState({
|
this.setState({
|
||||||
discoveredHsUrl: "",
|
|
||||||
discoveredIsUrl: "",
|
|
||||||
discoveryError: "",
|
discoveryError: "",
|
||||||
findingHomeserver: false,
|
findingHomeserver: false,
|
||||||
});
|
});
|
||||||
} else if (state === AutoDiscovery.SUCCESS) {
|
} else if (state === AutoDiscovery.SUCCESS) {
|
||||||
this.setState({
|
this.setState({
|
||||||
discoveredHsUrl: discovery["m.homeserver"].base_url,
|
|
||||||
discoveredIsUrl:
|
|
||||||
discovery["m.identity_server"].state === AutoDiscovery.SUCCESS
|
|
||||||
? discovery["m.identity_server"].base_url
|
|
||||||
: "",
|
|
||||||
discoveryError: "",
|
discoveryError: "",
|
||||||
findingHomeserver: false,
|
findingHomeserver: false,
|
||||||
});
|
});
|
||||||
|
this.onServerConfigChange({
|
||||||
|
hsUrl: discovery["m.homeserver"].base_url,
|
||||||
|
isUrl: discovery["m.identity_server"].state === AutoDiscovery.SUCCESS
|
||||||
|
? discovery["m.identity_server"].base_url
|
||||||
|
: "",
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.warn("Unknown state for m.homeserver in discovery response: ", discovery);
|
console.warn("Unknown state for m.homeserver in discovery response: ", discovery);
|
||||||
this.setState({
|
this.setState({
|
||||||
discoveredHsUrl: "",
|
|
||||||
discoveredIsUrl: "",
|
|
||||||
discoveryError: _t("Unknown failure discovering homeserver"),
|
discoveryError: _t("Unknown failure discovering homeserver"),
|
||||||
findingHomeserver: false,
|
findingHomeserver: false,
|
||||||
});
|
});
|
||||||
|
@ -429,8 +439,8 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
_initLoginLogic: function(hsUrl, isUrl) {
|
_initLoginLogic: function(hsUrl, isUrl) {
|
||||||
const self = this;
|
const self = this;
|
||||||
hsUrl = hsUrl || this.state.enteredHomeserverUrl;
|
hsUrl = hsUrl || this.state.enteredHsUrl;
|
||||||
isUrl = isUrl || this.state.enteredIdentityServerUrl;
|
isUrl = isUrl || this.state.enteredIsUrl;
|
||||||
|
|
||||||
const fallbackHsUrl = hsUrl === this.props.defaultHsUrl ? this.props.fallbackHsUrl : null;
|
const fallbackHsUrl = hsUrl === this.props.defaultHsUrl ? this.props.fallbackHsUrl : null;
|
||||||
|
|
||||||
|
@ -440,8 +450,8 @@ module.exports = React.createClass({
|
||||||
this._loginLogic = loginLogic;
|
this._loginLogic = loginLogic;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
enteredHomeserverUrl: hsUrl,
|
enteredHsUrl: hsUrl,
|
||||||
enteredIdentityServerUrl: isUrl,
|
enteredIsUrl: isUrl,
|
||||||
busy: true,
|
busy: true,
|
||||||
loginIncorrect: false,
|
loginIncorrect: false,
|
||||||
});
|
});
|
||||||
|
@ -507,8 +517,8 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
if (err.cors === 'rejected') {
|
if (err.cors === 'rejected') {
|
||||||
if (window.location.protocol === 'https:' &&
|
if (window.location.protocol === 'https:' &&
|
||||||
(this.state.enteredHomeserverUrl.startsWith("http:") ||
|
(this.state.enteredHsUrl.startsWith("http:") ||
|
||||||
!this.state.enteredHomeserverUrl.startsWith("http"))
|
!this.state.enteredHsUrl.startsWith("http"))
|
||||||
) {
|
) {
|
||||||
errorText = <span>
|
errorText = <span>
|
||||||
{ _t("Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. " +
|
{ _t("Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. " +
|
||||||
|
@ -532,7 +542,7 @@ module.exports = React.createClass({
|
||||||
{
|
{
|
||||||
'a': (sub) => {
|
'a': (sub) => {
|
||||||
return <a target="_blank" rel="noopener"
|
return <a target="_blank" rel="noopener"
|
||||||
href={this.state.enteredHomeserverUrl}
|
href={this.state.enteredHsUrl}
|
||||||
>{ sub }</a>;
|
>{ sub }</a>;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -572,7 +582,7 @@ module.exports = React.createClass({
|
||||||
break;
|
break;
|
||||||
case ServerType.PREMIUM:
|
case ServerType.PREMIUM:
|
||||||
serverDetails = <ModularServerConfig
|
serverDetails = <ModularServerConfig
|
||||||
customHsUrl={this.state.discoveredHsUrl || this.props.customHsUrl}
|
customHsUrl={this.state.enteredHsUrl}
|
||||||
defaultHsUrl={this.props.defaultHsUrl}
|
defaultHsUrl={this.props.defaultHsUrl}
|
||||||
defaultIsUrl={this.props.defaultIsUrl}
|
defaultIsUrl={this.props.defaultIsUrl}
|
||||||
onServerConfigChange={this.onServerConfigChange}
|
onServerConfigChange={this.onServerConfigChange}
|
||||||
|
@ -581,8 +591,8 @@ module.exports = React.createClass({
|
||||||
break;
|
break;
|
||||||
case ServerType.ADVANCED:
|
case ServerType.ADVANCED:
|
||||||
serverDetails = <ServerConfig
|
serverDetails = <ServerConfig
|
||||||
customHsUrl={this.state.discoveredHsUrl || this.props.customHsUrl}
|
customHsUrl={this.state.enteredHsUrl}
|
||||||
customIsUrl={this.state.discoveredIsUrl || this.props.customIsUrl}
|
customIsUrl={this.state.enteredIsUrl}
|
||||||
defaultHsUrl={this.props.defaultHsUrl}
|
defaultHsUrl={this.props.defaultHsUrl}
|
||||||
defaultIsUrl={this.props.defaultIsUrl}
|
defaultIsUrl={this.props.defaultIsUrl}
|
||||||
onServerConfigChange={this.onServerConfigChange}
|
onServerConfigChange={this.onServerConfigChange}
|
||||||
|
@ -657,7 +667,7 @@ module.exports = React.createClass({
|
||||||
onPhoneNumberBlur={this.onPhoneNumberBlur}
|
onPhoneNumberBlur={this.onPhoneNumberBlur}
|
||||||
onForgotPasswordClick={this.props.onForgotPasswordClick}
|
onForgotPasswordClick={this.props.onForgotPasswordClick}
|
||||||
loginIncorrect={this.state.loginIncorrect}
|
loginIncorrect={this.state.loginIncorrect}
|
||||||
hsUrl={this.state.enteredHomeserverUrl}
|
hsUrl={this.state.enteredHsUrl}
|
||||||
disableSubmit={this.state.findingHomeserver}
|
disableSubmit={this.state.findingHomeserver}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue