package route import ( "net/http" oidc "forge.cadoles.com/wpetit/goweb-oidc" "forge.cadoles.com/wpetit/goweb-oidc/internal/config" "github.com/pkg/errors" "gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/middleware/container" ) func handleLogin(w http.ResponseWriter, r *http.Request) { ctn := container.Must(r.Context()) client := oidc.Must(ctn) client.Login(w, r) } func handleLoginCallback(w http.ResponseWriter, r *http.Request) { ctx := r.Context() idToken, err := oidc.IDToken(w, r) if err != nil { logger.Error(ctx, "could not retrieve idToken", logger.E(errors.WithStack(err))) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } ctn := container.Must(ctx) conf := config.Must(ctn) logger.Info(ctx, "user logged in", logger.F("sub", idToken.Subject)) http.Redirect(w, r, conf.HTTP.PublicBaseURL+"/", http.StatusSeeOther) }