From 75328cf0819f767d33e93ca2b86d6ddfe92ceadd Mon Sep 17 00:00:00 2001 From: tangbin Date: Thu, 14 May 2020 11:34:02 +0800 Subject: [PATCH] clear yunionauth cookie --- pkg/apigateway/handler/auth.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/apigateway/handler/auth.go b/pkg/apigateway/handler/auth.go index 606ca38689..7692b4ebc3 100644 --- a/pkg/apigateway/handler/auth.go +++ b/pkg/apigateway/handler/auth.go @@ -439,8 +439,12 @@ func getCookie(r *http.Request, name string) string { } } -func clearCookie(w http.ResponseWriter, name string) { +func clearCookie(w http.ResponseWriter, name string, domain string) { cookie := &http.Cookie{Name: name, Expires: time.Now(), Path: "/", MaxAge: -1, HttpOnly: false} + if len(domain) > 0 { + cookie.Domain = domain + } + http.SetCookie(w, cookie) } @@ -541,7 +545,7 @@ func (h *AuthHandlers) postLogoutHandler(ctx context.Context, w http.ResponseWri if len(tid) > 0 { clientman.TokenMan.Remove(tid) } - clearCookie(w, constants.YUNION_AUTH_COOKIE) + clearCookie(w, constants.YUNION_AUTH_COOKIE, options.Options.CookieDomain) appsrv.Send(w, "") }