Skip to content

Commit

Permalink
feat(gateway): logout redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
caryxychen committed May 16, 2022
1 parent dd2ba70 commit d963985
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/gateway/api/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ package api
import (
"fmt"
"github.com/emicklei/go-restful"
"k8s.io/apiserver/pkg/endpoints/handlers/responsewriters"
"net/http"
"tkestack.io/tke/pkg/gateway/token"
"tkestack.io/tke/pkg/util/log"
)

// Empty defines a data structure containing nothing.
Expand All @@ -39,14 +39,19 @@ func registerLogoutRoute(container *restful.Container) {
GET("/").
Doc("logout current user").
Operation("doLogout").
Returns(http.StatusOK, "Ok", Empty{}).
Returns(http.StatusFound, "Found", Empty{}).
To(handleLogoutFunc()))
container.Add(ws)
}

func handleLogoutFunc() func(*restful.Request, *restful.Response) {
return func(request *restful.Request, response *restful.Response) {
token.DeleteCookie(response.ResponseWriter)
responsewriters.WriteRawJSON(http.StatusOK, Empty{}, response.ResponseWriter)
returnTo := request.QueryParameter("return_to")
if returnTo == "" {
returnTo = "/tkestack"
}
log.Debugf("redirect to '%s'", returnTo)
http.Redirect(response.ResponseWriter, request.Request, returnTo, http.StatusFound)
}
}

0 comments on commit d963985

Please sign in to comment.