goweb-oidc/internal/route/logout.go

38 lines
836 B
Go
Raw Normal View History

2020-05-20 10:43:12 +02:00
package route
import (
"net/http"
oidc "forge.cadoles.com/wpetit/goweb-oidc"
"forge.cadoles.com/wpetit/goweb-oidc/internal/config"
2020-05-20 10:43:12 +02:00
"github.com/pkg/errors"
2020-05-22 16:03:59 +02:00
"gitlab.com/wpetit/goweb/logger"
2020-05-20 10:43:12 +02:00
"gitlab.com/wpetit/goweb/middleware/container"
"gitlab.com/wpetit/goweb/service/session"
)
func handleLogout(w http.ResponseWriter, r *http.Request) {
2020-05-22 16:03:59 +02:00
ctx := r.Context()
ctn := container.Must(ctx)
conf := config.Must(ctn)
2020-05-20 10:43:12 +02:00
sess, err := session.Must(ctn).Get(w, r)
if err != nil {
panic(errors.Wrap(err, "could not retrieve session"))
}
if err := sess.Delete(w, r); err != nil {
panic(errors.Wrap(err, "could not delete session"))
}
client := oidc.Must(ctn)
2020-05-22 16:03:59 +02:00
logger.Info(
ctx,
"logging out user",
logger.F("postLogoutURL", conf.OIDC.PostLogoutRedirectURL),
)
client.Logout(w, r, conf.OIDC.PostLogoutRedirectURL)
2020-05-20 10:43:12 +02:00
}