Handle WEB_DOMAIN for login
Turns out .well-known routes are CORS-enabled
This commit is contained in:
parent
463ec48a8d
commit
49c7ccb0cb
2 changed files with 35 additions and 12 deletions
22
src/locales/en.po
generated
22
src/locales/en.po
generated
|
@ -1345,7 +1345,7 @@ msgid "Accounts…"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/components/nav-menu.jsx:363
|
#: src/components/nav-menu.jsx:363
|
||||||
#: src/pages/login.jsx:166
|
#: src/pages/login.jsx:189
|
||||||
#: src/pages/status.jsx:792
|
#: src/pages/status.jsx:792
|
||||||
#: src/pages/welcome.jsx:64
|
#: src/pages/welcome.jsx:64
|
||||||
msgid "Log in"
|
msgid "Log in"
|
||||||
|
@ -1740,7 +1740,7 @@ msgstr ""
|
||||||
#: src/components/shortcuts-settings.jsx:75
|
#: src/components/shortcuts-settings.jsx:75
|
||||||
#: src/components/shortcuts-settings.jsx:84
|
#: src/components/shortcuts-settings.jsx:84
|
||||||
#: src/components/shortcuts-settings.jsx:122
|
#: src/components/shortcuts-settings.jsx:122
|
||||||
#: src/pages/login.jsx:170
|
#: src/pages/login.jsx:193
|
||||||
msgid "Instance"
|
msgid "Instance"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -2368,7 +2368,7 @@ msgstr "Login required."
|
||||||
|
|
||||||
#: src/compose.jsx:90
|
#: src/compose.jsx:90
|
||||||
#: src/pages/http-route.jsx:91
|
#: src/pages/http-route.jsx:91
|
||||||
#: src/pages/login.jsx:247
|
#: src/pages/login.jsx:270
|
||||||
msgid "Go home"
|
msgid "Go home"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -3052,32 +3052,32 @@ msgstr ""
|
||||||
msgid "No lists yet."
|
msgid "No lists yet."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/pages/login.jsx:86
|
#: src/pages/login.jsx:109
|
||||||
#: src/pages/login.jsx:99
|
#: src/pages/login.jsx:122
|
||||||
msgid "Failed to register application"
|
msgid "Failed to register application"
|
||||||
msgstr "Failed to register application"
|
msgstr "Failed to register application"
|
||||||
|
|
||||||
#: src/pages/login.jsx:185
|
#: src/pages/login.jsx:208
|
||||||
msgid "instance domain"
|
msgid "instance domain"
|
||||||
msgstr "instance domain"
|
msgstr "instance domain"
|
||||||
|
|
||||||
#: src/pages/login.jsx:209
|
#: src/pages/login.jsx:232
|
||||||
msgid "e.g. “mastodon.social”"
|
msgid "e.g. “mastodon.social”"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/pages/login.jsx:220
|
#: src/pages/login.jsx:243
|
||||||
msgid "Failed to log in. Please try again or try another instance."
|
msgid "Failed to log in. Please try again or try another instance."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/pages/login.jsx:232
|
#: src/pages/login.jsx:255
|
||||||
msgid "Continue with {selectedInstanceText}"
|
msgid "Continue with {selectedInstanceText}"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/pages/login.jsx:233
|
#: src/pages/login.jsx:256
|
||||||
msgid "Continue"
|
msgid "Continue"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/pages/login.jsx:241
|
#: src/pages/login.jsx:264
|
||||||
msgid "Don't have an account? Create one!"
|
msgid "Don't have an account? Create one!"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,32 @@ function Login() {
|
||||||
|
|
||||||
const submitInstance = (instanceURL) => {
|
const submitInstance = (instanceURL) => {
|
||||||
if (!instanceURL) return;
|
if (!instanceURL) return;
|
||||||
store.local.set('instanceURL', instanceURL);
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
// WEB_DOMAIN vs LOCAL_DOMAIN negotiation time
|
||||||
|
// https://docs.joinmastodon.org/admin/config/#web_domain
|
||||||
|
try {
|
||||||
|
const res = await fetch(`https://${instanceURL}/.well-known/host-meta`); // returns XML
|
||||||
|
const text = await res.text();
|
||||||
|
// Parse XML
|
||||||
|
const parser = new DOMParser();
|
||||||
|
const xmlDoc = parser.parseFromString(text, 'text/xml');
|
||||||
|
// Get Link[template]
|
||||||
|
const link = xmlDoc.getElementsByTagName('Link')[0];
|
||||||
|
const template = link.getAttribute('template');
|
||||||
|
const url = URL.parse(template);
|
||||||
|
const { host } = url; // host includes the port
|
||||||
|
if (instanceURL !== host) {
|
||||||
|
console.log(`💫 ${instanceURL} -> ${host}`);
|
||||||
|
instanceURL = host;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Silently fail
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
store.local.set('instanceURL', instanceURL);
|
||||||
|
|
||||||
setUIState('loading');
|
setUIState('loading');
|
||||||
try {
|
try {
|
||||||
const { client_id, client_secret, vapid_key } =
|
const { client_id, client_secret, vapid_key } =
|
||||||
|
|
Loading…
Add table
Reference in a new issue