Documentation
¶
Index ¶
- Variables
- func CreateMiscreantCookieCipher(cookieSecret []byte) func(s *CookieStore) error
- func ExtendDeadline(ttl time.Duration) time.Time
- func MarshalSession(s *SessionState, c aead.Cipher) (string, error)
- type CSRFStore
- type CookieStore
- func (s *CookieStore) ClearCSRF(rw http.ResponseWriter, req *http.Request)
- func (s *CookieStore) ClearSession(rw http.ResponseWriter, req *http.Request)
- func (s *CookieStore) GetCSRF(req *http.Request) (*http.Cookie, error)
- func (s *CookieStore) LoadSession(req *http.Request) (*SessionState, error)
- func (s *CookieStore) SaveSession(rw http.ResponseWriter, req *http.Request, sessionState *SessionState) error
- func (s *CookieStore) SetCSRF(rw http.ResponseWriter, req *http.Request, val string)
- type MockCSRFStore
- type MockSessionStore
- type SessionState
- type SessionStore
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidSession = errors.New("invalid session")
ErrInvalidSession is an error for invalid sessions.
var ( // ErrLifetimeExpired is an error for the lifetime deadline expiring ErrLifetimeExpired = errors.New("user lifetime expired") )
Functions ¶
func CreateMiscreantCookieCipher ¶
func CreateMiscreantCookieCipher(cookieSecret []byte) func(s *CookieStore) error
CreateMiscreantCookieCipher creates a new miscreant cipher with the cookie secret
func ExtendDeadline ¶
ExtendDeadline returns the time extended by a given duration
func MarshalSession ¶
func MarshalSession(s *SessionState, c aead.Cipher) (string, error)
MarshalSession marshals the session state as JSON, encrypts the JSON using the given cipher, and base64-encodes the result
Types ¶
type CSRFStore ¶
type CSRFStore interface { SetCSRF(http.ResponseWriter, *http.Request, string) GetCSRF(*http.Request) (*http.Cookie, error) ClearCSRF(http.ResponseWriter, *http.Request) }
CSRFStore has the functions for setting, getting, and clearing the CSRF cookie
type CookieStore ¶
type CookieStore struct { Name string CSRFCookieName string CookieExpire time.Duration CookieRefresh time.Duration CookieSecure bool CookieHTTPOnly bool CookieDomain string CookieCipher aead.Cipher SessionLifetimeTTL time.Duration }
CookieStore represents all the cookie related configurations
func NewCookieStore ¶
func NewCookieStore(cookieName string, optFuncs ...func(*CookieStore) error) (*CookieStore, error)
NewCookieStore returns a new session with ciphers for each of the cookie secrets
func (*CookieStore) ClearCSRF ¶
func (s *CookieStore) ClearCSRF(rw http.ResponseWriter, req *http.Request)
ClearCSRF clears the CSRF cookie from the request
func (*CookieStore) ClearSession ¶
func (s *CookieStore) ClearSession(rw http.ResponseWriter, req *http.Request)
ClearSession clears the session cookie from a request
func (*CookieStore) LoadSession ¶
func (s *CookieStore) LoadSession(req *http.Request) (*SessionState, error)
LoadSession returns a SessionState from the cookie in the request.
func (*CookieStore) SaveSession ¶
func (s *CookieStore) SaveSession(rw http.ResponseWriter, req *http.Request, sessionState *SessionState) error
SaveSession saves a session state to a request sessions.
func (*CookieStore) SetCSRF ¶
func (s *CookieStore) SetCSRF(rw http.ResponseWriter, req *http.Request, val string)
SetCSRF sets the CSRFCookie creates a CSRF cookie in a given request
type MockCSRFStore ¶
MockCSRFStore is a mock implementation of the CSRF store interface
func (*MockCSRFStore) ClearCSRF ¶
func (ms *MockCSRFStore) ClearCSRF(http.ResponseWriter, *http.Request)
ClearCSRF clears the ResponseCSRF string
func (*MockCSRFStore) SetCSRF ¶
func (ms *MockCSRFStore) SetCSRF(rw http.ResponseWriter, req *http.Request, val string)
SetCSRF sets the ResponseCSRF string to a val
type MockSessionStore ¶
type MockSessionStore struct { ResponseSession string Session *SessionState SaveError error LoadError error }
MockSessionStore is a mock implementation of the SessionStore interface
func (*MockSessionStore) ClearSession ¶
func (ms *MockSessionStore) ClearSession(http.ResponseWriter, *http.Request)
ClearSession clears the ResponseSession
func (*MockSessionStore) LoadSession ¶
func (ms *MockSessionStore) LoadSession(*http.Request) (*SessionState, error)
LoadSession returns the session and a error
func (*MockSessionStore) SaveSession ¶
func (ms *MockSessionStore) SaveSession(http.ResponseWriter, *http.Request, *SessionState) error
SaveSession returns a save error.
type SessionState ¶
type SessionState struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` IDToken string `json:"id_token"` // https://openid.net/specs/openid-connect-core-1_0.html#TokenResponse RefreshDeadline time.Time `json:"refresh_deadline"` LifetimeDeadline time.Time `json:"lifetime_deadline"` ValidDeadline time.Time `json:"valid_deadline"` GracePeriodStart time.Time `json:"grace_period_start"` Email string `json:"email"` User string `json:"user"` Groups []string `json:"groups"` }
SessionState is our object that keeps track of a user's session state
func UnmarshalSession ¶
func UnmarshalSession(value string, c aead.Cipher) (*SessionState, error)
UnmarshalSession takes the marshaled string, base64-decodes into a byte slice, decrypts the byte slice using the pased cipher, and unmarshals the resulting JSON into a session state struct
func (*SessionState) LifetimePeriodExpired ¶
func (s *SessionState) LifetimePeriodExpired() bool
LifetimePeriodExpired returns true if the lifetime has expired
func (*SessionState) RefreshPeriodExpired ¶
func (s *SessionState) RefreshPeriodExpired() bool
RefreshPeriodExpired returns true if the refresh period has expired
func (*SessionState) ValidationPeriodExpired ¶
func (s *SessionState) ValidationPeriodExpired() bool
ValidationPeriodExpired returns true if the validation period has expired
type SessionStore ¶
type SessionStore interface { ClearSession(http.ResponseWriter, *http.Request) LoadSession(*http.Request) (*SessionState, error) SaveSession(http.ResponseWriter, *http.Request, *SessionState) error }
SessionStore has the functions for setting, getting, and clearing the Session cookie