session

package
v0.9.0-rc.53 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	CookieName = "pwikit_sessionid"
	CookieAge  = 14 * 24 * time.Hour

	Salt = "django.contrib.sessions.SessionStore"

	KeyLength = 32

	AuthUserID      = "_auth_user_id"
	AuthUserBackend = "_auth_user_backend"
	AuthUserHash    = "_auth_user_hash"
)

Variables

View Source
var (
	ErrBadSignature      = errors.New("session: signature does not match")
	ErrMalformed         = errors.New("session: malformed signed value")
	ErrSignatureExpired  = errors.New("session: signature expired")
	ErrUnsupportedFormat = errors.New("session: unsupported payload format")
)

Functions

func NewKey

func NewKey() (string, error)

func UserID

func UserID(data map[string]any) (string, bool)

Types

type Signer

type Signer struct {
	Key       string
	Fallbacks []string
	Salt      string
}

func (Signer) Sign

func (s Signer) Sign(value string) string

func (Signer) Unsign

func (s Signer) Unsign(signed string) (string, error)

type Store

type Store struct {
	Signer TimestampSigner
}

func New

func New(secretKey string, fallbacks ...string) *Store

func (*Store) AuthHash

func (s *Store) AuthHash(passwordHash string) string

AuthHash ties a session to the password it was opened under. Without this check a stolen session keeps working after the password changes.

func (*Store) AuthHashMatches

func (s *Store) AuthHashMatches(passwordHash, want string) bool

AuthHashMatches tries the fallback secrets too, so a key rotation does not sign everyone out.

func (*Store) Decode

func (s *Store) Decode(sessionData string) (map[string]any, error)

func (*Store) Encode

func (s *Store) Encode(data map[string]any) (string, error)

type TimestampSigner

type TimestampSigner struct {
	Signer
	Now func() time.Time
}

func (TimestampSigner) Sign

func (s TimestampSigner) Sign(value string) string

func (TimestampSigner) Unsign

func (s TimestampSigner) Unsign(signed string, maxAge time.Duration) (string, error)

Jump to

Keyboard shortcuts

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