sessions: github.com/adam-hanna/sessions Index | Files | Directories

package sessions

import "github.com/adam-hanna/sessions"

Index

Package Files

service.go service_interface.go service_util.go

Constants

const (
    // DefaultExpirationDuration sets the default session expiration duration
    DefaultExpirationDuration = 3 * 24 * time.Hour // 3 days
)

type Options Uses

type Options struct {
    ExpirationDuration time.Duration
}

Options defines the behavior of the session service

type Service Uses

type Service struct {
    // contains filtered or unexported fields
}

Service provides session service for http servers

func New Uses

func New(store store.ServiceInterface, auth auth.ServiceInterface, transport transport.ServiceInterface, options Options) *Service

New returns a new session service

func (*Service) ClearUserSession Uses

func (s *Service) ClearUserSession(userSession *user.Session, w http.ResponseWriter) error

ClearUserSession is used to remove the user session from the store and clear the cookies on the ResponseWriter.

This method should be called when a user logs out, for example.

func (*Service) ExtendUserSession Uses

func (s *Service) ExtendUserSession(userSession *user.Session, r *http.Request, w http.ResponseWriter) error

ExtendUserSession extends the ExpiresAt of a session by the Options.ExpirationDuration

Note that this function must be called, manually! Extension of user session expiry's does not happen automatically!

func (*Service) GetUserSession Uses

func (s *Service) GetUserSession(r *http.Request) (*user.Session, error)

GetUserSession returns a user session from a request. This method only returns valid sessions. Therefore, \ sessions that have expired, or that fail signature verification will return a nil pointer to a user.Session

func (*Service) IssueUserSession Uses

func (s *Service) IssueUserSession(userID string, json string, w http.ResponseWriter) (*user.Session, error)

IssueUserSession grants a new user session, writes that session info to the store \ and writes the session on the http.ResponseWriter.

This method should be called when a user logs in, for example.

type ServiceInterface Uses

type ServiceInterface interface {
    IssueUserSession(userID string, json string, w http.ResponseWriter) (*user.Session, error)
    ClearUserSession(userSession *user.Session, w http.ResponseWriter) error
    GetUserSession(r *http.Request) (*user.Session, error)
    ExtendUserSession(userSession *user.Session, r *http.Request, w http.ResponseWriter) error
}

ServiceInterface defines the methods performed by the session service

Directories

PathSynopsis
auth
store
transport
user

Package sessions imports 6 packages (graph). Updated 2020-05-23. Refresh now. Tools for package owners.