Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serverName to be specified in URL #17824

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
82 changes: 45 additions & 37 deletions src/vector/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function loadApp(fragParams: {}) {
(platform as VectorBasePlatform).startUpdater();

// Don't bother loading the app until the config is verified
const config = await verifyServerConfig();
const config = await verifyServerConfig(fragParams);

// Before we continue, let's see if we're supposed to do an SSO redirect
const [userId] = await Lifecycle.getStoredSessionOwner();
Expand Down Expand Up @@ -188,7 +188,7 @@ export async function loadApp(fragParams: {}) {
/>;
}

async function verifyServerConfig() {
async function verifyServerConfig(fragParams) {
let validatedConfig;
try {
console.log("Verifying homeserver configuration");
Expand All @@ -202,48 +202,56 @@ async function verifyServerConfig() {
// care if they are syntactically correct though, so we shove them through the .well-known
// validators for that purpose.

let discoveryResult = null;

const config = SdkConfig.get();
let wkConfig = config['default_server_config']; // overwritten later under some conditions
const serverName = config['default_server_name'];
const hsUrl = config['default_hs_url'];
const isUrl = config['default_is_url'];

const incompatibleOptions = [wkConfig, serverName, hsUrl].filter(i => !!i);
if (incompatibleOptions.length > 1) {
// noinspection ExceptionCaughtLocallyJS
throw newTranslatableError(_td(
"Invalid configuration: can only specify one of default_server_config, default_server_name, " +
"or default_hs_url.",
));
}
if (incompatibleOptions.length < 1) {
// noinspection ExceptionCaughtLocallyJS
throw newTranslatableError(_td("Invalid configuration: no default server specified."));
}

if (hsUrl) {
console.log("Config uses a default_hs_url - constructing a default_server_config using this information");
console.warn(
"DEPRECATED CONFIG OPTION: In the future, default_hs_url will not be accepted. Please use " +
"default_server_config instead.",
);
let serverName = null;
if (fragParams.serverName) {
aaronraimist marked this conversation as resolved.
Show resolved Hide resolved
serverName = fragParams.serverName;
aaronraimist marked this conversation as resolved.
Show resolved Hide resolved
} else {
serverName = config['default_server_name'];
const hsUrl = config['default_hs_url'];
const isUrl = config['default_is_url'];

const incompatibleOptions = [wkConfig, serverName, hsUrl].filter(i => !!i);
if (incompatibleOptions.length > 1) {
// noinspection ExceptionCaughtLocallyJS
throw newTranslatableError(_td(
"Invalid configuration: can only specify one of default_server_config, default_server_name, " +
"or default_hs_url.",
));
}
if (incompatibleOptions.length < 1) {
// noinspection ExceptionCaughtLocallyJS
throw newTranslatableError(_td("Invalid configuration: no default server specified."));
}

wkConfig = {
"m.homeserver": {
"base_url": hsUrl,
},
};
if (isUrl) {
wkConfig["m.identity_server"] = {
"base_url": isUrl,
if (hsUrl) {
console.log("Config uses a default_hs_url - constructing a default_server_config using this " +
"information");
aaronraimist marked this conversation as resolved.
Show resolved Hide resolved
console.warn(
"DEPRECATED CONFIG OPTION: In the future, default_hs_url will not be accepted. Please use " +
"default_server_config instead.",
);

wkConfig = {
"m.homeserver": {
"base_url": hsUrl,
},
};
if (isUrl) {
wkConfig["m.identity_server"] = {
"base_url": isUrl,
};
}
}
}

let discoveryResult = null;
if (wkConfig) {
console.log("Config uses a default_server_config - validating object");
discoveryResult = await AutoDiscovery.fromDiscoveryConfig(wkConfig);
if (wkConfig) {
console.log("Config uses a default_server_config - validating object");
discoveryResult = await AutoDiscovery.fromDiscoveryConfig(wkConfig);
}
}

if (serverName) {
Expand Down