session

package
v0.0.0-...-5615e58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CheckPath = "/sessions/me"
)
View Source
const DefaultSessionCookieName = "hive_session_manager"

DefaultSessionCookieName returns the default cookie name for the hive session.

Variables

View Source
var (
	ErrNoActiveSessionFound = herodot.ErrUnauthorized.WithReason("No active session was found in this request.")
)

Functions

func MockCookieClient

func MockCookieClient(t *testing.T) *http.Client

func MockGetSession

func MockGetSession(t *testing.T, reg Registry) httprouter.Handle

func MockHydrateCookieClient

func MockHydrateCookieClient(t *testing.T, c *http.Client, u string)

func MockMakeAuthenticatedRequest

func MockMakeAuthenticatedRequest(t *testing.T, reg Registry, router *httprouter.Router, req *http.Request) ([]byte, *http.Response)

func MockSessionCreateHandler

func MockSessionCreateHandler(t *testing.T, reg Registry) httprouter.Handle

func MockSetSession

func MockSetSession(t *testing.T, reg Registry) httprouter.Handle

func RedirectOnAuthenticated

func RedirectOnAuthenticated(c configuration.Provider) httprouter.Handle

Types

type Configuration

type Configuration interface {
	SessionLifespan() time.Duration
	SessionSecrets() [][]byte
}

type Device

type Device struct {
	UserAgent string `json:"user_agent"`
	// IP string `json:"ip"`
	SeenAt []time.Time `json:"seen_at" faker:"time_types"`
}

type Handler

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

func NewHandler

func NewHandler(
	r Registry,
	h herodot.Writer,
) *Handler

func (*Handler) IsNotAuthenticated

func (h *Handler) IsNotAuthenticated(wrap httprouter.Handle, onAuthenticated httprouter.Handle) httprouter.Handle

func (*Handler) RegisterAdminRoutes

func (h *Handler) RegisterAdminRoutes(admin *x.RouterAdmin)

func (*Handler) RegisterPublicRoutes

func (h *Handler) RegisterPublicRoutes(public *x.RouterPublic)

type HandlerProvider

type HandlerProvider interface {
	SessionHandler() *Handler
}

type ManagementProvider

type ManagementProvider interface {
	SessionManager() Manager
}

type Manager

type Manager interface {
	// Get retrieves a session from the store.
	Get(ctx context.Context, sid string) (*Session, error)

	// Create adds a session to the store.
	Create(ctx context.Context, s *Session) error

	// Delete removes a session from the store
	Delete(ctx context.Context, sid string) error

	CreateToRequest(context.Context, *identity.Identity, http.ResponseWriter, *http.Request) (*Session, error)

	// SaveToRequest creates an HTTP session using cookies.
	SaveToRequest(context.Context, *Session, http.ResponseWriter, *http.Request) error

	// FetchFromRequest creates an HTTP session using cookies.
	FetchFromRequest(context.Context, *http.Request) (*Session, error)

	// PurgeFromRequest removes an HTTP session.
	PurgeFromRequest(context.Context, http.ResponseWriter, *http.Request) error
}

Manager handles identity sessions.

type ManagerHTTP

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

func NewManagerHTTP

func NewManagerHTTP(
	c Configuration,
	r Registry,
	m Manager,
) *ManagerHTTP

func (*ManagerHTTP) CreateToRequest

func (s *ManagerHTTP) CreateToRequest(ctx context.Context, i *identity.Identity, w http.ResponseWriter, r *http.Request) (*Session, error)

func (*ManagerHTTP) FetchFromRequest

func (s *ManagerHTTP) FetchFromRequest(ctx context.Context, r *http.Request) (*Session, error)

func (*ManagerHTTP) PurgeFromRequest

func (s *ManagerHTTP) PurgeFromRequest(ctx context.Context, w http.ResponseWriter, r *http.Request) error

func (*ManagerHTTP) SaveToRequest

func (s *ManagerHTTP) SaveToRequest(ctx context.Context, session *Session, w http.ResponseWriter, r *http.Request) error

func (*ManagerHTTP) WithManager

func (s *ManagerHTTP) WithManager(m Manager)

type ManagerMemory

type ManagerMemory struct {
	*ManagerHTTP
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewManagerMemory

func NewManagerMemory(c Configuration, r Registry) *ManagerMemory

func (*ManagerMemory) Create

func (s *ManagerMemory) Create(ctx context.Context, session *Session) error

func (*ManagerMemory) Delete

func (s *ManagerMemory) Delete(ctx context.Context, sid string) error

func (*ManagerMemory) Get

func (s *ManagerMemory) Get(ctx context.Context, sid string) (*Session, error)

type ManagerSQL

type ManagerSQL struct {
	*ManagerHTTP
	// contains filtered or unexported fields
}

func NewManagerSQL

func NewManagerSQL(c Configuration, r Registry, db *sqlx.DB) *ManagerSQL

func (*ManagerSQL) Create

func (s *ManagerSQL) Create(ctx context.Context, session *Session) error

func (*ManagerSQL) Delete

func (s *ManagerSQL) Delete(ctx context.Context, sid string) error

func (*ManagerSQL) Get

func (s *ManagerSQL) Get(ctx context.Context, sid string) (*Session, error)

type Registry

type Registry interface {
	CookieManager() sessions.Store
	SessionManager() Manager
	identity.PoolProvider
}

type Session

type Session struct {
	SID             string             `json:"sid"`
	ExpiresAt       time.Time          `json:"expires_at" faker:"time_type"`
	AuthenticatedAt time.Time          `json:"authenticated_at" faker:"time_type"`
	IssuedAt        time.Time          `json:"issued_at" faker:"time_type"`
	Identity        *identity.Identity `json:"identity"`
	// contains filtered or unexported fields
}

func NewSession

func NewSession(i *identity.Identity, r *http.Request, c Configuration) *Session

func (*Session) GetIdentity

func (s *Session) GetIdentity() *identity.Identity

func (*Session) ResetModifiedIdentityFlag

func (s *Session) ResetModifiedIdentityFlag() *Session

func (*Session) UpdateIdentity

func (s *Session) UpdateIdentity(i *identity.Identity) *Session

func (*Session) WasIdentityModified

func (s *Session) WasIdentityModified() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL