guesstimate/internal/route/logout.go

41 lines
940 B
Go
Raw Normal View History

2020-08-08 15:04:59 +02:00
package route
import (
"net/http"
"forge.cadoles.com/Cadoles/guesstimate/internal/session"
"github.com/pkg/errors"
"forge.cadoles.com/Cadoles/guesstimate/internal/config"
oidc "forge.cadoles.com/wpetit/goweb-oidc"
"gitlab.com/wpetit/goweb/logger"
"gitlab.com/wpetit/goweb/middleware/container"
)
func handleLogout(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctn := container.Must(ctx)
conf := config.Must(ctn)
client := oidc.Must(ctn)
logger.Info(
ctx,
"logging out user",
logger.F("postLogoutURL", conf.OIDC.PostLogoutRedirectURL),
)
if err := session.ClearUserEmail(w, r, false); err != nil {
panic(errors.WithStack(err))
}
client.Logout(w, r, conf.OIDC.PostLogoutRedirectURL)
}
func handleLogoutRedirect(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctn := container.Must(ctx)
conf := config.Must(ctn)
http.Redirect(w, r, conf.HTTP.FrontendURL, http.StatusSeeOther)
}