cookie

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoltSessionsBucket = "sessions"
	BoltRevokedBucket  = "revoked"
)
View Source
const (
	DefaultCookieName = "whawty-nginx-sso"
	DefaultExpire     = 24 * time.Hour
)
View Source
const (
	DeviceTypeMobile  = "Mobile"
	DeviceTypeTablet  = "Tablet"
	DeviceTypeDesktop = "Desktop"
	DeviceTypeBot     = "Bot"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentInfo added in v0.3.1

type AgentInfo struct {
	Name       string `json:"name"`
	OS         string `json:"os"`
	DeviceType string `json:"device-type"`
}

type BoltBackend added in v0.3.1

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

func NewBoltBackend added in v0.3.1

func NewBoltBackend(conf *BoltBackendConfig, prom prometheus.Registerer) (*BoltBackend, error)

func (*BoltBackend) CollectGarbage added in v0.3.1

func (b *BoltBackend) CollectGarbage() (cnt uint, err error)

func (*BoltBackend) IsRevoked added in v0.3.1

func (b *BoltBackend) IsRevoked(session Session) (isRevoked bool, err error)

func (*BoltBackend) ListRevoked added in v0.3.1

func (b *BoltBackend) ListRevoked() (list SessionList, err error)

func (*BoltBackend) ListUser added in v0.3.1

func (b *BoltBackend) ListUser(username string) (list SessionFullList, err error)

func (*BoltBackend) LoadRevocations added in v0.3.1

func (b *BoltBackend) LoadRevocations(list SessionList) (cnt uint, err error)

func (*BoltBackend) Name added in v0.3.1

func (b *BoltBackend) Name() string

func (*BoltBackend) Revoke added in v0.3.1

func (b *BoltBackend) Revoke(session Session) error

func (*BoltBackend) RevokeID added in v0.3.1

func (b *BoltBackend) RevokeID(username string, id ulid.ULID) error

func (*BoltBackend) Save added in v0.3.1

func (b *BoltBackend) Save(session SessionFull) error

type BoltBackendConfig added in v0.3.1

type BoltBackendConfig struct {
	Path string `yaml:"path"`
}

type BoltSession added in v0.3.1

type BoltSession struct {
	SessionBase
	Agent AgentInfo `json:"agent"`
}

type Config

type Config struct {
	Name    string                 `yaml:"name"`
	Domain  string                 `yaml:"domain"`
	Secure  bool                   `yaml:"secure"`
	Expire  time.Duration          `yaml:"expire"`
	Keys    []SignerVerifierConfig `yaml:"keys"`
	Backend StoreBackendConfig     `yaml:"backend"`
}

type Ed25519Config

type Ed25519Config struct {
	PrivKeyFile *string `yaml:"private-key"`
	PrivKeyData *string `yaml:"private-key-data"`
	PubKeyFile  *string `yaml:"public-key"`
	PubKeyData  *string `yaml:"public-key-data"`
}

type Ed25519SignerVerifier

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

func NewEd25519SignerVerifier

func NewEd25519SignerVerifier(context string, conf *Ed25519Config) (*Ed25519SignerVerifier, error)

func (Ed25519SignerVerifier) Algo

func (s Ed25519SignerVerifier) Algo() string

func (Ed25519SignerVerifier) CanSign

func (s Ed25519SignerVerifier) CanSign() bool

func (Ed25519SignerVerifier) Sign

func (s Ed25519SignerVerifier) Sign(payload []byte) ([]byte, error)

func (Ed25519SignerVerifier) Verify

func (s Ed25519SignerVerifier) Verify(payload, signature []byte) error

type InMemoryBackend added in v0.3.1

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

func NewInMemoryBackend added in v0.3.1

func NewInMemoryBackend(conf *InMemoryBackendConfig, prom prometheus.Registerer) (*InMemoryBackend, error)

func (*InMemoryBackend) CollectGarbage added in v0.3.1

func (b *InMemoryBackend) CollectGarbage() (uint, error)

func (*InMemoryBackend) IsRevoked added in v0.3.1

func (b *InMemoryBackend) IsRevoked(session Session) (bool, error)

func (*InMemoryBackend) ListRevoked added in v0.3.1

func (b *InMemoryBackend) ListRevoked() (list SessionList, err error)

func (*InMemoryBackend) ListUser added in v0.3.1

func (b *InMemoryBackend) ListUser(username string) (list SessionFullList, err error)

func (*InMemoryBackend) LoadRevocations added in v0.3.1

func (b *InMemoryBackend) LoadRevocations(list SessionList) (cnt uint, err error)

func (*InMemoryBackend) Name added in v0.3.1

func (b *InMemoryBackend) Name() string

func (*InMemoryBackend) Revoke added in v0.3.1

func (b *InMemoryBackend) Revoke(session Session) error

func (*InMemoryBackend) RevokeID added in v0.3.1

func (b *InMemoryBackend) RevokeID(username string, id ulid.ULID) error

func (*InMemoryBackend) Save added in v0.3.1

func (b *InMemoryBackend) Save(session SessionFull) error

type InMemoryBackendConfig added in v0.3.1

type InMemoryBackendConfig struct {
}

type InMemorySession added in v0.3.1

type InMemorySession struct {
	SessionBase
	Agent AgentInfo `json:"agent"`
}

type InMemorySessionMap added in v0.3.1

type InMemorySessionMap map[ulid.ULID]InMemorySession

type Options

type Options struct {
	Name   string
	MaxAge int
	Domain string
	Secure bool
}

type Session added in v0.3.1

type Session struct {
	ID ulid.ULID `json:"id"`
	SessionBase
}

func (Session) CreatedAt added in v0.3.1

func (s Session) CreatedAt() time.Time

func (Session) ExpiresAt added in v0.3.1

func (s Session) ExpiresAt() time.Time

type SessionBase added in v0.3.1

type SessionBase struct {
	Username string `json:"u"`
	Expires  int64  `json:"e"`
}

func (*SessionBase) IsExpired added in v0.3.1

func (s *SessionBase) IsExpired() bool

func (*SessionBase) SetExpiry added in v0.3.1

func (s *SessionBase) SetExpiry(lifetime time.Duration)

type SessionFull added in v0.3.1

type SessionFull struct {
	Session
	Agent AgentInfo `json:"agent"`
}

func (SessionFull) CreatedAt added in v0.3.1

func (s SessionFull) CreatedAt() time.Time

func (SessionFull) ExpiresAt added in v0.3.1

func (s SessionFull) ExpiresAt() time.Time

type SessionFullList added in v0.3.1

type SessionFullList []SessionFull

func (SessionFullList) MarshalJSON added in v0.3.1

func (l SessionFullList) MarshalJSON() ([]byte, error)

type SessionList added in v0.3.1

type SessionList []Session

func (SessionList) MarshalJSON added in v0.3.1

func (l SessionList) MarshalJSON() ([]byte, error)

type SignedRevocationList added in v0.3.1

type SignedRevocationList struct {
	Revoked   json.RawMessage `json:"revoked"`
	Signature []byte          `json:"signature"`
}

type SignerVerifier

type SignerVerifier interface {
	Algo() string
	CanSign() bool
	Sign(payload []byte) ([]byte, error)
	Verify(payload, signature []byte) error
}

type SignerVerifierConfig

type SignerVerifierConfig struct {
	Name    string         `yaml:"name"`
	Ed25519 *Ed25519Config `yaml:"ed25519"`
}

type Store added in v0.3.1

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

func NewStore added in v0.3.1

func NewStore(conf *Config, prom prometheus.Registerer, infoLog, dbgLog *log.Logger) (*Store, error)

func (*Store) ListRevoked added in v0.3.1

func (st *Store) ListRevoked() (result SignedRevocationList, err error)

func (*Store) ListUser added in v0.3.1

func (st *Store) ListUser(username string) (SessionFullList, error)

func (*Store) New added in v0.3.1

func (st *Store) New(username string, ai AgentInfo) (value string, opts Options, err error)

func (*Store) Options added in v0.3.1

func (st *Store) Options() (opts Options)

func (*Store) Revoke added in v0.3.1

func (st *Store) Revoke(session Session) error

func (*Store) RevokeID added in v0.3.1

func (st *Store) RevokeID(username string, id ulid.ULID) error

func (*Store) Verify added in v0.3.1

func (st *Store) Verify(value string) (s Session, err error)

type StoreBackend added in v0.3.1

type StoreBackend interface {
	Name() string
	Save(session SessionFull) error
	ListUser(username string) (SessionFullList, error)
	Revoke(session Session) error
	RevokeID(username string, id ulid.ULID) error
	IsRevoked(session Session) (bool, error)
	ListRevoked() (SessionList, error)
	LoadRevocations(SessionList) (uint, error)
	CollectGarbage() (uint, error)
}

type StoreBackendConfig added in v0.3.1

type StoreBackendConfig struct {
	GCInterval time.Duration          `yaml:"gc-interval"`
	Sync       *StoreSyncConfig       `yaml:"sync"`
	InMemory   *InMemoryBackendConfig `yaml:"in-memory"`
	Bolt       *BoltBackendConfig     `yaml:"bolt"`
}

type StoreSyncConfig added in v0.3.1

type StoreSyncConfig struct {
	Interval  time.Duration        `yaml:"interval"`
	BaseURL   string               `yaml:"base-url"`
	HTTPHost  string               `yaml:"http-host"`
	TLSConfig *tlsconfig.TLSConfig `yaml:"tls"`
	Token     string               `yaml:"token"`
}

type Value

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

func MakeValue added in v0.3.1

func MakeValue(id ulid.ULID, s SessionBase) (v *Value, err error)

func (*Value) FromString

func (v *Value) FromString(encoded string) (err error)

func (*Value) Session added in v0.3.1

func (v *Value) Session() (s Session, err error)

func (*Value) String

func (v *Value) String() string

Jump to

Keyboard shortcuts

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