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

Support .well-known autodiscovery in the js-sdk #799

Merged
merged 9 commits into from
Dec 12, 2018

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Dec 4, 2018

Note to the reviewer: This also includes a change for supporting ES6 modules. See 7e0752b for details.


It's much more useful here than in the react-sdk as it can be reused by more applications. This is also required to make the react-sdk a little easier to manage .well-known lookups as soon it'll be doing it in several places.

Automatic discovery is an abstract concept in the spec and could include more than .well-known in the future, so this is made to be generic enough to support future mechanisms and other resources to discover. There's also a ton of comments (more than normally needed) as people may wish to use this as a reference in their own implementation and it doesn't hurt to explain what everything is doing.

This abstraction ends up manifesting itself as returning a .well-known response-like object. Although the object we return is our own format, we mimic .well-known for maximum compatibility.

Many of the functions are air lifted from the react-sdk and modified to work within the confines of the js-sdk.

It's much more useful here than in the react-sdk as it can be reused by more applications. This is also required to make the react-sdk a little easier to manage .well-known lookups as soon it'll be doing it in several places. 

Automatic discovery is an abstract concept in the spec and could include more than .well-known in the future, so this is made to be generic enough to support future mechanisms and other resources to discover. There's also a ton of comments (more than normally needed) as people may wish to use this as a reference in their own implementation and it doesn't hurt to explain what everything is doing.

Many of the functions are air lifted from the react-sdk and modified to work within the confines of the js-sdk.
@turt2live turt2live requested a review from a team December 4, 2018 20:49
@turt2live
Copy link
Member Author

Looks like the build is very unhappy about ES6 somewhere - will look into this before requesting review.

@turt2live turt2live removed the request for review from a team December 5, 2018 03:03
turt2live added a commit to matrix-org/matrix-react-sdk that referenced this pull request Dec 5, 2018
Fixes element-hq/element-web#7724

The `default_server_name` from the config gets displayed in the "Login with my [server] matrix ID" dropdown when the default server is being used. At this point, we also discourage the use of the `default_hs_url` and `default_is_url` options because we do an implicit .well-known lookup to configure the client based on the `default_server_name`. If the URLs are still present in the config, we'll honour them and won't do a .well-known lookup when the URLs are mixed with the new server_name option. Users will be warned if the `default_server_name` does not match the `default_hs_url` if both are supplied. Users are additionally prevented from logging in, registering, and resetting their password if the implicit .well-known check fails - this is to prevent people from doing actions against the wrong homeserver.

This relies on matrix-org/matrix-js-sdk#799 as we now do auto discovery in two places. Instead of bringing the .well-known out to its own utility class in the react-sdk, we might as well drag it out to the js-sdk.
@turt2live turt2live self-assigned this Dec 5, 2018
So we can start using ES6 dependencies without figuring out how to update babel. 

`uglify-es` is compatible with `uglify-js@3` (we were using `@2`) , which is why the same command is used. This commit includes changes to the command line to make the thing run the same as before too.
@turt2live turt2live requested a review from a team December 7, 2018 23:54
@dbkr
Copy link
Member

dbkr commented Dec 10, 2018

So the thing with having to update uglify here is that a recursive dependency (tr46 of whatwg-url) has exported ES6 rather than ES5. It looks like we're going to have to do something about this as this is the second time this has come up recently. Doing this will mean we will, in turn, start exporting ES6 from js-sdk which will cause the same problem for any other libraries that depend on us.

We should make a conscious decision about what to do - I've filed #803 for this

Copy link
Contributor

@bwindels bwindels left a comment

Choose a reason for hiding this comment

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

otherwise lgtm

src/autodiscovery.js Show resolved Hide resolved
src/autodiscovery.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@turt2live
Copy link
Member Author

I'm probably going to change this such that it spits out ES5 as a bundle so we can punt the ES5/6 issue down the road. It might not be pretty though, sorry.

@turt2live
Copy link
Member Author

@bwindels please take another look. I've changed the URL handling, and as a consequence removed all the ES6 stuff.

package-lock.json Outdated Show resolved Hide resolved
Copy link
Contributor

@bwindels bwindels left a comment

Choose a reason for hiding this comment

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

other than comments, lgtm

@turt2live turt2live merged commit c445290 into develop Dec 12, 2018
@turt2live turt2live deleted the travis/well-known-improvements branch December 12, 2018 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants