Files
wonderwall/pkg/handler/session_fallback.go
Trong Huu Nguyen 5a50ba7c3a feat: support multiple ingresses
Replace hardcoded callback URLs with dynamic generation
of URLs based on incoming requests. These are validated against
a pre-registered list of ingresses for which Wonderwall is considered
authorative for.

We also preserve the cookie behaviour; the most specific ingress path
and domain is used for the cookies.

The `url` package has been moved to the `handler` package, and its
implementation refactored slightly for readability and DRY.
2022-08-17 20:43:56 +02:00

28 lines
776 B
Go

package handler
import (
"net/http"
"time"
"github.com/nais/wonderwall/pkg/session"
)
func (h *Handler) SetSessionFallback(w http.ResponseWriter, r *http.Request, data *session.Data, expiresIn time.Duration) error {
store := h.cookieStore(w, r)
return store.Write(data, expiresIn)
}
func (h *Handler) GetSessionFallback(w http.ResponseWriter, r *http.Request) (*session.Data, error) {
store := h.cookieStore(w, r)
return store.Read(r.Context())
}
func (h *Handler) DeleteSessionFallback(w http.ResponseWriter, r *http.Request) {
store := h.cookieStore(w, r)
store.Delete()
}
func (h *Handler) cookieStore(w http.ResponseWriter, r *http.Request) session.CookieStore {
return session.NewCookie(w, r, h.Crypter, h.Provider, h.CookieOptions.WithPath(h.Path(r)))
}