func (s *SessionStore) cookieForSession(ss *sessions.SessionState) ([]byte, error) {
	if s.Minimal && (ss.AccessToken != "" || ss.IDToken != "" || ss.RefreshToken != "") {
		minimal := *ss
		minimal.AccessToken = ""
		minimal.IDToken = ""
		minimal.RefreshToken = ""
		return minimal.EncodeSessionState(s.CookieCipher, true)
	}
	return ss.EncodeSessionState(s.CookieCipher, true)
}
cookieForSession serializes a session state for storage in a cookie
package cookie
import (
	"errors"
	"fmt"
	"net/http"
	"regexp"
	"time"
	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
	pkgcookies "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/cookies"
	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/encryption"
	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
)
const (
	maxCookieLength = 4000
)
var _ sessions.SessionStore = &SessionStore{}
type SessionStore struct {
	Cookie       *options.Cookie
	CookieCipher encryption.Cipher
	Minimal      bool
}
func (s *SessionStore) Save(rw http.ResponseWriter, req *http.Request, ss *sessions.SessionState) error {
	if ss.CreatedAt == nil || ss.CreatedAt.IsZero() {
		ss.CreatedAtNow()
	}
	value, err := s.cookieForSession(ss)
	if err != nil {
		return err
	}
	return s.setSessionCookie(rw, req, value, *ss.CreatedAt)
}
func (s *SessionStore) Load(req *http.Request) (*sessions.SessionState, error) {
	c, err := loadCookie(req, s.Cookie.Name)
	if err != nil {
		return nil, err
	}
	val, _, ok := encryption.Validate(c, s.Cookie.Secret, s.Cookie.Expire)
	if !ok {
		return nil, errors.New("cookie signature not valid")
	}
	session, err := sessions.DecodeSessionState(val, s.CookieCipher, true)
	if err != nil {
		return nil, err
	}
	return session, nil
}
func (s *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) error {
	var cookieNameRegex = regexp.MustCompile(fmt.Sprintf("^%s(_\\d+)?$", s.Cookie.Name))
	for _, c := range req.Cookies() {
		if cookieNameRegex.MatchString(c.Name) {
			clearCookie := s.makeCookie(req, c.Name, "", time.Hour*-1, time.Now())
			http.SetCookie(rw, clearCookie)
		}
	}
	return nil
}