func (s *SessionStore) makeSessionCookie(req *http.Request, value string, now time.Time) []*http.Cookie {
	if value != "" {
		value = encryption.SignedValue(s.CookieOptions.CookieSecret, s.CookieOptions.CookieName, value, now)
	}
	c := s.makeCookie(req, s.CookieOptions.CookieName, value, s.CookieOptions.CookieExpire, now)
	if len(c.Value) > 4096-len(s.CookieOptions.CookieName) {
		return splitCookie(c)
	}
	return []*http.Cookie{c}
}
makeSessionCookie creates an http.Cookie containing the authenticated user's
authentication details
package cookie
import (
	"errors"
	"fmt"
	"net/http"
	"regexp"
	"strings"
	"time"
	"github.com/pusher/oauth2_proxy/pkg/apis/options"
	"github.com/pusher/oauth2_proxy/pkg/apis/sessions"
	"github.com/pusher/oauth2_proxy/pkg/cookies"
	"github.com/pusher/oauth2_proxy/pkg/encryption"
	"github.com/pusher/oauth2_proxy/pkg/sessions/utils"
)
const (
	maxCookieLength = 3840
)
var _ sessions.SessionStore = &SessionStore{}
type SessionStore struct {
	CookieOptions *options.CookieOptions
	CookieCipher  *encryption.Cipher
}
func (s *SessionStore) Save(rw http.ResponseWriter, req *http.Request, ss *sessions.SessionState) error {
	if ss.CreatedAt.IsZero() {
		ss.CreatedAt = time.Now()
	}
	value, err := utils.CookieForSession(ss, s.CookieCipher)
	if err != nil {
		return err
	}
	s.setSessionCookie(rw, req, value, ss.CreatedAt)
	return nil
}
func (s *SessionStore) Load(req *http.Request) (*sessions.SessionState, error) {
	c, err := loadCookie(req, s.CookieOptions.CookieName)
	if err != nil {
		return nil, fmt.Errorf("Cookie %q not present", s.CookieOptions.CookieName)
	}
	val, _, ok := encryption.Validate(c, s.CookieOptions.CookieSecret, s.CookieOptions.CookieExpire)
	if !ok {
		return nil, errors.New("Cookie Signature not valid")
	}
	session, err := utils.SessionFromCookie(val, s.CookieCipher)
	if err != nil {
		return nil, err
	}
	return session, nil
}
func (s *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) error {
	var cookies []*http.Cookie
	var cookieNameRegex = regexp.MustCompile(fmt.Sprintf("^%s(_\\d+)?$", s.CookieOptions.CookieName))
	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)
			cookies = append(cookies, clearCookie)
		}
	}
	return nil
}
func (s *SessionStore) setSessionCookie(rw http.ResponseWriter, req *http.Request, val string, created time.Time) {
	for _, c := range s.makeSessionCookie(req, val, created) {
		http.SetCookie(rw, c)
	}
}