From f191488338ec7efbdbb16eeecac88fdc6e53f79b Mon Sep 17 00:00:00 2001 From: imp2002 Date: Wed, 22 Mar 2023 00:15:17 +0800 Subject: [PATCH] feat: support `popup` mode in OAuth (#1668) * feat: support `popup` mode in OAuth * feat: sendMessage when popup window closed * fix: fix param name error --- web/src/auth/LoginPage.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/web/src/auth/LoginPage.js b/web/src/auth/LoginPage.js index 4cc4fe2f..197e217c 100644 --- a/web/src/auth/LoginPage.js +++ b/web/src/auth/LoginPage.js @@ -204,6 +204,13 @@ class LoginPage extends React.Component { } } + sendPopupData(message, redirectUri) { + const params = new URLSearchParams(this.props.location.search); + if (params.get("popup") === "1") { + window.opener.postMessage(message, redirectUri); + } + } + postCodeLoginAction(res) { const application = this.getApplicationObj(); const ths = this; @@ -243,6 +250,7 @@ class LoginPage extends React.Component { } } else { Setting.goToLink(`${oAuthParams.redirectUri}${concatChar}code=${code}&state=${oAuthParams.state}`); + this.sendPopupData({type: "loginSuccess", data: {code: code, state: oAuthParams.state}}, oAuthParams.redirectUri); } } } @@ -640,6 +648,12 @@ class LoginPage extends React.Component { this.onFinish(values); } + if (params.get("popup") === "1") { + window.addEventListener("beforeunload", () => { + this.sendPopupData({type: "windowClosed"}, params.get("redirect_uri")); + }); + } + if (application.enableAutoSignin) { const values = {}; values["application"] = application.name;