sessions

package
v7.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLockNotObtained = errors.New("lock: not obtained")
View Source
var ErrNotLocked = errors.New("tried to release not existing lock")

Functions

This section is empty.

Types

type Lock added in v7.2.0

type Lock interface {
	// Obtain obtains the lock on the distributed
	// lock resource if no lock exists yet.
	// Otherwise it will return ErrLockNotObtained
	Obtain(ctx context.Context, expiration time.Duration) error
	// Peek returns true if the lock currently exists
	// Otherwise it returns false.
	Peek(ctx context.Context) (bool, error)
	// Refresh refreshes the expiration time of the lock,
	// if is still applied.
	// Otherwise it will return ErrNotLocked
	Refresh(ctx context.Context, expiration time.Duration) error
	// Release removes the existing lock,
	// Otherwise it will return ErrNotLocked
	Release(ctx context.Context) error
}

Lock is an interface for controlling session locks

type NoOpLock added in v7.2.0

type NoOpLock struct{}

func (*NoOpLock) Obtain added in v7.2.0

func (l *NoOpLock) Obtain(_ context.Context, _ time.Duration) error

func (*NoOpLock) Peek added in v7.2.0

func (l *NoOpLock) Peek(_ context.Context) (bool, error)

func (*NoOpLock) Refresh added in v7.2.0

func (l *NoOpLock) Refresh(_ context.Context, _ time.Duration) error

func (*NoOpLock) Release added in v7.2.0

func (l *NoOpLock) Release(_ context.Context) error

type SessionState

type SessionState struct {
	CreatedAt *time.Time `msgpack:"ca,omitempty"`
	ExpiresOn *time.Time `msgpack:"eo,omitempty"`

	AccessToken  string `msgpack:"at,omitempty"`
	IDToken      string `msgpack:"it,omitempty"`
	RefreshToken string `msgpack:"rt,omitempty"`

	Nonce []byte `msgpack:"n,omitempty"`

	Email             string   `msgpack:"e,omitempty"`
	User              string   `msgpack:"u,omitempty"`
	Groups            []string `msgpack:"g,omitempty"`
	PreferredUsername string   `msgpack:"pu,omitempty"`

	// Internal helpers, not serialized
	Clock clock.Clock `msgpack:"-"`
	Lock  Lock        `msgpack:"-"`
}

SessionState is used to store information about the currently authenticated user session

func DecodeSessionState

func DecodeSessionState(data []byte, c encryption.Cipher, compressed bool) (*SessionState, error)

DecodeSessionState decodes a LZ4 compressed MessagePack into a Session State

func (*SessionState) Age

func (s *SessionState) Age() time.Duration

Age returns the age of a session

func (*SessionState) CheckNonce added in v7.1.3

func (s *SessionState) CheckNonce(hashed string) bool

CheckNonce compares the Nonce against a potential hash of it

func (*SessionState) CreatedAtNow added in v7.2.0

func (s *SessionState) CreatedAtNow()

CreatedAtNow sets a SessionState's CreatedAt to now

func (*SessionState) EncodeSessionState

func (s *SessionState) EncodeSessionState(c encryption.Cipher, compress bool) ([]byte, error)

EncodeSessionState returns an encrypted, lz4 compressed, MessagePack encoded session

func (*SessionState) ExpiresIn added in v7.2.0

func (s *SessionState) ExpiresIn(d time.Duration)

ExpiresIn sets an expiration a certain duration from CreatedAt. CreatedAt will be set to time.Now if it is unset.

func (*SessionState) GetClaim

func (s *SessionState) GetClaim(claim string) []string

func (*SessionState) IsExpired

func (s *SessionState) IsExpired() bool

IsExpired checks whether the session has expired

func (*SessionState) ObtainLock added in v7.2.0

func (s *SessionState) ObtainLock(ctx context.Context, expiration time.Duration) error

func (*SessionState) PeekLock added in v7.2.0

func (s *SessionState) PeekLock(ctx context.Context) (bool, error)

func (*SessionState) RefreshLock added in v7.2.0

func (s *SessionState) RefreshLock(ctx context.Context, expiration time.Duration) error

func (*SessionState) ReleaseLock added in v7.2.0

func (s *SessionState) ReleaseLock(ctx context.Context) error

func (*SessionState) SetExpiresOn added in v7.2.0

func (s *SessionState) SetExpiresOn(exp time.Time)

SetExpiresOn sets an expiration

func (*SessionState) String

func (s *SessionState) String() string

String constructs a summary of the session state

type SessionStore

type SessionStore interface {
	Save(rw http.ResponseWriter, req *http.Request, s *SessionState) error
	Load(req *http.Request) (*SessionState, error)
	Clear(rw http.ResponseWriter, req *http.Request) error
	VerifyConnection(ctx context.Context) error
}

SessionStore is an interface to storing user sessions in the proxy

Jump to

Keyboard shortcuts

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