From 651d0f24c76a7c61b63155acf8a24119a59ad9cd Mon Sep 17 00:00:00 2001 From: pennae Date: Sun, 7 Aug 2022 01:47:07 +0200 Subject: fenix login is actually a lot simpler but it *must* be done over https with trusted certificates --- web/js/main.js | 48 ++++++++++++------------------------------------ 1 file changed, 12 insertions(+), 36 deletions(-) (limited to 'web/js') diff --git a/web/js/main.js b/web/js/main.js index 3c1f23a..27d3a1a 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -13,7 +13,7 @@ class Channel { window.addEventListener( 'WebChannelMessageToContent', ev => { - if (ev.detail.message.error) { + if (ev.detail && ev.detail.message.error) { for (const wait in this.waiting) { this.waiting[wait].reject(new Error(ev.detail.message.error)); } @@ -80,6 +80,15 @@ class Channel { }); } + loadOauthCredentials(code, state) { + this._send('account_updates', 'fxaccounts:oauth_login', { + code, + state, + redirect: "urn:ietf:wg:oauth:2.0:oob:oauth-redirect-webchannel", + action: "signin" + }); + } + passwordChanged(email, uid) { this._send('account_updates', 'fxaccounts:change_password', { email, @@ -717,21 +726,6 @@ customElements.define('do-generate-invite', GenerateInvite); ////////////////////////////////////////// class FenixSignin extends HTMLElement { - constructor(session) { - super(); - const shadow = this.attachShadow({mode: 'open'}); - shadow.replaceChildren( - $("styles").cloneNode(true), - $("tpl-fenix-signin-warning").content.cloneNode(true)); - shadow.querySelector("#signin").onclick = wrapHandler(async ev => { - ev.preventDefault(); - switchTo(new FenixSigninEnter()); - }); - } -} -customElements.define('do-fenix-signin', FenixSignin); - -class FenixSigninEnter extends HTMLElement { constructor(session) { super(); const shadow = this.attachShadow({mode: 'open'}); @@ -787,21 +781,7 @@ class FenixSigninEnter extends HTMLElement { code_challenge: param("code_challenge"), }); - console.log(`browser.tabs.executeScript({code: \` - port = browser.runtime.connectNative("mozacWebchannel"); - port.postMessage({ - id: "account_updates", - message: { - command: "fxaccounts:oauth_login", - data: { - "code": "${code.code}", - "state": "${code.state}", - "redirect": "urn:ietf:wg:oauth:2.0:oob:oauth-redirect-webchannel", - "action": "signin" - }, - messageId: 1, - }}); - \`});`); + channel.loadOauthCredentials(code.code, code.state); switchTo(new FenixSignin()); } finally { @@ -809,7 +789,7 @@ class FenixSigninEnter extends HTMLElement { } } } -customElements.define('do-fenix-signin-enter', FenixSigninEnter); +customElements.define('do-fenix-signin', FenixSignin); ////////////////////////////////////////// // initialization @@ -822,10 +802,6 @@ const isAndroid = /Android/.test(navigator.userAgent); document.body.onload = async () => { showMessage("Loading ...", "animate"); - if (isAndroid) { - document.head.appendChild($("tpl-fenix-style").content); - } - try { let resp = await fetch("/.well-known/fxa-client-configuration"); if (!resp.ok) throw new Error(resp.statusText); -- cgit v1.2.3