Documentation ¶
Overview ¶
Package sesh is a session management library written in Go. It uses a postgres table to track current sessions and their expiration, and it logs all session lifecycle events.
Index ¶
- func ContextWithTestSession(ctx context.Context, session Session) context.Context
- type Session
- type Sessions
- func (s Sessions) AuthenticateUserAndAddToTestRequest(r *http.Request, accountID string) error
- func (s Sessions) AuthenticationMiddleware() func(http.Handler) http.Handler
- func (s Sessions) UserDidAuthenticate(w http.ResponseWriter, accountID string) (sessionKey string, err error)
- func (s Sessions) UserDidLogout(w http.ResponseWriter, r *http.Request) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Session ¶
Session contains all the information about a given user session This type is inserted into the context by the AuthenticationMiddleware
func SessionFromContext ¶
SessionFromContext pulls the current sesh.Session object out of the context This function is all that is required in your handlers to get the current session information
type Sessions ¶
type Sessions struct {
// contains filtered or unexported fields
}
Sessions manage browser sessions with a db table and logs all significant lifecycle events
func NewSessions ¶
func NewSessions(db *sqlx.DB, log domain.LogService, timeout time.Duration, useSecureCookie bool) Sessions
NewSessions returns a configured Sessions, taking an existing sqlx.DB as the first argument.
func (Sessions) AuthenticateUserAndAddToTestRequest ¶ added in v0.0.3
AuthenticateUserAndAddToTestRequest is not used in the operation of sesh. It is intended to be used in your tests to create a valid session for a request, alleviating you from having to make a login request as part of the test.
func (Sessions) AuthenticationMiddleware ¶
AuthenticationMiddleware reads the session cookie and verifies that the request is being made by someone with a valid session It then stores the current session in the context, which can be retrieved with SessionFromContext(ctx) If the session is invalid it responds with an error and does not call any further handlers.
func (Sessions) UserDidAuthenticate ¶
func (s Sessions) UserDidAuthenticate(w http.ResponseWriter, accountID string) (sessionKey string, err error)
UserDidAuthenticate creates a new session and writes an HTTPOnly cookie to track that session it returns errors
func (Sessions) UserDidLogout ¶
UserDidLogout destroys the session and removes the session cookie. it returns errors