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
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
10 changes: 10 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,13 @@ Currently, the following UI feature flags are supported:
user.
* `UIFeature.roomHistorySettings` - Whether or not the room history settings are shown to the user.
This should only be used if the room history visibility options are managed by the server.

URL Parameters
==============

* `serverName` - Provide the default server used on the login and registration pages. Examples:
* https://app.element.io/#/login?serverName=kde.org
* https://app.element.io/#/register?serverName=kde.org
* `defaultUsername` - Provide the default username used on the login page. Example:
* https://app.element.io/#/login?defaultUsername=alice

84 changes: 47 additions & 37 deletions src/vector/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,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 @@ -183,7 +183,7 @@ export async function loadApp(fragParams: {}) {
/>;
}

async function verifyServerConfig() {
async function verifyServerConfig(fragParams) {
let validatedConfig;
try {
console.log("Verifying homeserver configuration");
Expand All @@ -197,48 +197,58 @@ 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
console.log("Using server_name from fragParams, ignoring config options.");
} 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",
);
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