From b42391c6ce11329148638de70859b55f7a512e3f Mon Sep 17 00:00:00 2001 From: DacongDA Date: Sat, 5 Jul 2025 22:48:44 +0800 Subject: [PATCH] feat: move needUpdatePassword to response's Data3 field to avoid refresh token conflict (#3931) --- controllers/account.go | 1 + controllers/auth.go | 10 +++++----- web/src/auth/AuthCallback.js | 8 ++++---- web/src/auth/LoginPage.js | 12 ++++++------ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/controllers/account.go b/controllers/account.go index f85ec21f..22fee923 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -42,6 +42,7 @@ type Response struct { Name string `json:"name"` Data interface{} `json:"data"` Data2 interface{} `json:"data2"` + Data3 interface{} `json:"data3"` } type Captcha struct { diff --git a/controllers/auth.go b/controllers/auth.go index ea9e180e..0f3ceafe 100644 --- a/controllers/auth.go +++ b/controllers/auth.go @@ -132,7 +132,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob if form.Type == ResponseTypeLogin { c.SetSessionUsername(userId) util.LogInfo(c.Ctx, "API: [%s] signed in", userId) - resp = &Response{Status: "ok", Msg: "", Data: userId, Data2: user.NeedUpdatePassword} + resp = &Response{Status: "ok", Msg: "", Data: userId, Data3: user.NeedUpdatePassword} } else if form.Type == ResponseTypeCode { clientId := c.Input().Get("clientId") responseType := c.Input().Get("responseType") @@ -154,7 +154,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob } resp = codeToResponse(code) - resp.Data2 = user.NeedUpdatePassword + resp.Data3 = user.NeedUpdatePassword if application.EnableSigninSession || application.HasPromptPage() { // The prompt page needs the user to be signed in c.SetSessionUsername(userId) @@ -168,7 +168,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob token, _ := object.GetTokenByUser(application, user, scope, nonce, c.Ctx.Request.Host) resp = tokenToResponse(token) - resp.Data2 = user.NeedUpdatePassword + resp.Data3 = user.NeedUpdatePassword } } else if form.Type == ResponseTypeDevice { authCache, ok := object.DeviceAuthMap.LoadAndDelete(form.UserCode) @@ -195,14 +195,14 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob object.DeviceAuthMap.Store(authCacheCast.UserName, deviceAuthCacheDeviceCodeCast) - resp = &Response{Status: "ok", Msg: "", Data: userId, Data2: user.NeedUpdatePassword} + resp = &Response{Status: "ok", Msg: "", Data: userId, Data3: user.NeedUpdatePassword} } else if form.Type == ResponseTypeSaml { // saml flow res, redirectUrl, method, err := object.GetSamlResponse(application, user, form.SamlRequest, c.Ctx.Request.Host) if err != nil { c.ResponseError(err.Error(), nil) return } - resp = &Response{Status: "ok", Msg: "", Data: res, Data2: map[string]interface{}{"redirectUrl": redirectUrl, "method": method, "needUpdatePassword": user.NeedUpdatePassword}} + resp = &Response{Status: "ok", Msg: "", Data: res, Data2: map[string]interface{}{"redirectUrl": redirectUrl, "method": method}, Data3: user.NeedUpdatePassword} if application.EnableSigninSession || application.HasPromptPage() { // The prompt page needs the user to be signed in diff --git a/web/src/auth/AuthCallback.js b/web/src/auth/AuthCallback.js index 2bafe5ae..9eab842e 100644 --- a/web/src/auth/AuthCallback.js +++ b/web/src/auth/AuthCallback.js @@ -166,7 +166,7 @@ class AuthCallback extends React.Component { const responseType = this.getResponseType(); const handleLogin = (res) => { if (responseType === "login") { - if (res.data2) { + if (res.data3) { sessionStorage.setItem("signinUrl", signinUrl); Setting.goToLinkSoft(this, `/forget/${applicationName}`); return; @@ -176,7 +176,7 @@ class AuthCallback extends React.Component { const link = Setting.getFromLink(); Setting.goToLink(link); } else if (responseType === "code") { - if (res.data2) { + if (res.data3) { sessionStorage.setItem("signinUrl", signinUrl); Setting.goToLinkSoft(this, `/forget/${applicationName}`); return; @@ -185,7 +185,7 @@ class AuthCallback extends React.Component { Setting.goToLink(`${oAuthParams.redirectUri}${concatChar}code=${code}&state=${oAuthParams.state}`); // Setting.showMessage("success", `Authorization code: ${res.data}`); } else if (responseType === "token" || responseType === "id_token") { - if (res.data2) { + if (res.data3) { sessionStorage.setItem("signinUrl", signinUrl); Setting.goToLinkSoft(this, `/forget/${applicationName}`); return; @@ -207,7 +207,7 @@ class AuthCallback extends React.Component { relayState: oAuthParams.relayState, }); } else { - if (res.data2.needUpdatePassword) { + if (res.data3) { sessionStorage.setItem("signinUrl", signinUrl); Setting.goToLinkSoft(this, `/forget/${applicationName}`); return; diff --git a/web/src/auth/LoginPage.js b/web/src/auth/LoginPage.js index 02962439..aebfdd42 100644 --- a/web/src/auth/LoginPage.js +++ b/web/src/auth/LoginPage.js @@ -496,9 +496,9 @@ class LoginPage extends React.Component { const responseType = values["type"]; if (responseType === "login") { - if (res.data2) { + if (res.data3) { sessionStorage.setItem("signinUrl", window.location.pathname + window.location.search); - Setting.goToLink(this, `/forget/${this.state.applicationName}`); + Setting.goToLinkSoft(this, `/forget/${this.state.applicationName}`); } Setting.showMessage("success", i18next.t("application:Logged in successfully")); this.props.onLoginSuccess(); @@ -510,9 +510,9 @@ class LoginPage extends React.Component { userCodeStatus: "success", }); } else if (responseType === "token" || responseType === "id_token") { - if (res.data2) { + if (res.data3) { sessionStorage.setItem("signinUrl", window.location.pathname + window.location.search); - Setting.goToLink(this, `/forget/${this.state.applicationName}`); + Setting.goToLinkSoft(this, `/forget/${this.state.applicationName}`); } const amendatoryResponseType = responseType === "token" ? "access_token" : responseType; const accessToken = res.data; @@ -522,9 +522,9 @@ class LoginPage extends React.Component { this.props.onLoginSuccess(window.location.href); return; } - if (res.data2.needUpdatePassword) { + if (res.data3) { sessionStorage.setItem("signinUrl", window.location.pathname + window.location.search); - Setting.goToLink(this, `/forget/${this.state.applicationName}`); + Setting.goToLinkSoft(this, `/forget/${this.state.applicationName}`); } if (res.data2.method === "POST") { this.setState({