sessions

package
v7.0.0-...-1c7ecba Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 11 Imported by: 0

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

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

type NoOpLock struct{}

func (*NoOpLock) Obtain

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

func (*NoOpLock) Peek

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

func (*NoOpLock) Refresh

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

func (*NoOpLock) Release

func (l *NoOpLock) Release(ctx 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

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

CheckNonce compares the Nonce against a potential hash of it

func (*SessionState) CreatedAtNow

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

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

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

func (*SessionState) PeekLock

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

func (*SessionState) RefreshLock

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

func (*SessionState) ReleaseLock

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

func (*SessionState) SetExpiresOn

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