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

Support .well-known discovery #2227

Merged
merged 6 commits into from
Nov 27, 2018
Merged

Support .well-known discovery #2227

merged 6 commits into from
Nov 27, 2018

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Oct 18, 2018

Fixes element-hq/element-web#7253

Note: this does not implement step 2 of the discovery process. This is because IPv6 addresses are difficult to verify this way. Instead, this will adopt any port number in the user's ID as part of the address it queries for a .well-known config. See matrix-org/matrix-spec-proposals#1700 for more information.

Here's it working for someone trying to log in with a not-matrix.org address (for example):
wellknown2

@turt2live turt2live requested a review from a team October 18, 2018 22:53
@Half-Shot
Copy link
Contributor

Can I be a pain and suggest that the discovery parts go in matrix-js-sdk. I can certainly think of projects which would benefit from this code and it would limit duping the same algo all over the place?

@turt2live
Copy link
Member Author

turt2live commented Oct 18, 2018

It would be nearly impossible to put the .well-known bits in the js-sdk and maintain a helpful UI, sorry.

Edit: unless anyone has bright ideas on how to do so, given all the potential surrounding the redesign.

@maxidorius
Copy link

maxidorius commented Oct 19, 2018

this does not implement step 2 of the discovery process.

and

this will adopt any port number in the user's ID as part of the address it queries for a .well-known config.

Then I'm afraid you are:

  • Not following The Spec.
  • Doing something that goes against recommended synapse setup.
  • Goes against the idea of .well-known which is to be independent of the service itself. This is a discovery mechanism.
  • Might force sysadmins to put a reverse-proxy on federation port.
  • Produce errors in clients which are not meant to handle self-signed certificates, which is the recommended and natural thing on federation port.
  • Will create a big(ger) mess with the whole dual port situation that already exists.
  • Will deviate from what other clients/libraries already implement and is already used in the wild, forcing sysadmins to now support two different systems.
  • Using Riot near-monopoly over the Matrix ecosystem to force a change down the community's throat, where current behaviour in The Spec was extensively discussed over several months and involved many actors.

There was a rationale why this was made this way, and I would strongly recommend you do not deviate from it in the slightest.

@maxidorius
Copy link

It would be nearly impossible to put the .well-known bits in the js-sdk and maintain a helpful UI, sorry.

Edit: unless anyone has bright ideas on how to do so, given all the potential surrounding the redesign.

Return an object that would give the outcome of the auto-discovery (ignore, fail prompt, fail error, ok, etc.) so the UI can react accordingly.

@Half-Shot
Copy link
Contributor

It would be nearly impossible to put the .well-known bits in the js-sdk and maintain a helpful UI, sorry.
Edit: unless anyone has bright ideas on how to do so, given all the potential surrounding the redesign.

Return an object that would give the outcome of the auto-discovery (ignore, fail prompt, fail error, ok, etc.) so the UI can react accordingly.

Basically this, but @turt2live thinks this might be quite difficult with the UX requirements in the spec so it may not be so simple.

Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

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

Looks good modulo comments here & over on the spec PR.


if (this.state.discoveredHsUrl) {
console.log("Rewriting username because the homeserver was discovered");
username = username.substring(1).split(":")[0];
Copy link
Member

Choose a reason for hiding this comment

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

Should we not just be sending the full mxid to the server?

Copy link
Member Author

Choose a reason for hiding this comment

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

this eventually gets passed along to /login as just the localpart. Here seemed like a good enough place to do the conversion is all.

Copy link
Member

Choose a reason for hiding this comment

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

hmm, where's that? I thought it just went through as 'user' in https://github.com/matrix-org/matrix-react-sdk/blob/master/src/Login.js#L130 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yea, around there. According to the spec ( https://matrix.org/docs/spec/client_server/r0.4.0.html#identifier-types ) it should work fine with the local part or user ID - I might have stumbled on a synapse bug (or I suck at testing)

Copy link
Member Author

Choose a reason for hiding this comment

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

My testing was flawed - will fix.

@@ -218,8 +233,12 @@ module.exports = React.createClass({
}).done();
},

onUsernameChanged: function(username) {
onUsernameChanged: function(username, endOfInput) {
Copy link
Member

Choose a reason for hiding this comment

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

I would be tempted to just have a separate onUsernameBlur rather than adding a param

return;
}

console.log("Verifying homeserver URL: " + hsUrl);
Copy link
Member

Choose a reason for hiding this comment

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

Presumably this would go if matrix-org/matrix-spec-proposals#1700 is approved?

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

// XXX: We don't verify the identity server URL because sydent doesn't register
// the route we need.

// console.log("Verifying identity server URL: " + isUrl);
Copy link
Member

Choose a reason for hiding this comment

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

I assume also unnecessary with matrix-org/matrix-spec-proposals#1700

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

customHsUrl={this.props.customHsUrl}
customIsUrl={this.props.customIsUrl}
customHsUrl={this.state.discoveredHsUrl || this.props.customHsUrl}
customIsUrl={this.state.discoveredIsUrl ||this.props.customIsUrl}
Copy link
Member

Choose a reason for hiding this comment

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

Should the value from .well-known be changing the default rather than setting custom URLs? You may still want to override the HS URL (eg. https://example.com/ -> https://example-test.com/) but having got the urls from .well-known essentially provides us a better default.

Copy link
Member Author

Choose a reason for hiding this comment

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

There was something that got in the way when I tried to set them explicitly the first time, however I think I might have fixed the bug towards the end of implementing this. I'll see if I can repurpose the custom properties instead of introducing new ones, while also maintaining the ability to override the discovered URL (for power users).

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's best to keep this as-is. It forces the UI to switch to "Custom Server", signifying that something happened. It isn't the best UX, but it is something.

@turt2live turt2live self-assigned this Oct 25, 2018
@turt2live turt2live requested a review from a team November 21, 2018 21:15
@turt2live turt2live removed their assignment Nov 22, 2018
Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

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

otherwise looks fine

const url = new URL("https://" + serverName);
this._tryWellKnownDiscovery(url.hostname);
} catch (e) {
console.error("Problem parsing URL or unhandled error doing .well-known discovery");
Copy link
Member

Choose a reason for hiding this comment

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

I think we've been converging on console.log("message", e) which does a sensible thing

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants