From 113c27db73edaeaf3c6081f1c89214c3d1b32da3 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sat, 2 Dec 2023 02:13:34 +0800 Subject: [PATCH] Improve logout's id_token_hint logic --- controllers/account.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/controllers/account.go b/controllers/account.go index 9ed2408d39d1..d335f6de8277 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -282,17 +282,15 @@ func (c *ApiController) Logout() { return } - affected, application, token, err := object.ExpireTokenByAccessToken(accessToken) + _, application, token, err := object.ExpireTokenByAccessToken(accessToken) if err != nil { c.ResponseError(err.Error()) return } - - if !affected { + if token == nil { c.ResponseError(c.T("token:Token not found, invalid accessToken")) return } - if application == nil { c.ResponseError(fmt.Sprintf(c.T("auth:The application: %s does not exist")), token.Application) return @@ -319,7 +317,15 @@ func (c *ApiController) Logout() { return } else { if application.IsRedirectUriValid(redirectUri) { - c.Ctx.Redirect(http.StatusFound, fmt.Sprintf("%s?state=%s", strings.TrimRight(redirectUri, "/"), state)) + redirectUrl := redirectUri + if state != "" { + if strings.Contains(redirectUri, "?") { + redirectUrl = fmt.Sprintf("%s&state=%s", strings.TrimSuffix(redirectUri, "/"), state) + } else { + redirectUrl = fmt.Sprintf("%s?state=%s", strings.TrimSuffix(redirectUri, "/"), state) + } + } + c.Ctx.Redirect(http.StatusFound, redirectUrl) } else { c.ResponseError(fmt.Sprintf(c.T("token:Redirect URI: %s doesn't exist in the allowed Redirect URI list"), redirectUri)) return