Documentation
¶
Overview ¶
Deprecated: Use github.com/vormadev/vorma/kit/cookies instead. This package is retained for backward compatibility with existing sessions.
Package signedcookie provides a secure cookie manager for Go web applications.
Index ¶
Constants ¶
const SecretSize = 32 // SecretSize is the size, in bytes, of a cookie secret.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseCookie ¶
BaseCookie is a type alias for http.Cookie. It is used for providing and overriding default cookie settings. Note that the Name, HttpOnly, and Secure fields are ignored. The expires field is not ignored, but it will be overridden by an explicitly set TTL.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles the creation, signing, and verification of secure cookies.
func NewManager ¶
func NewManager(secrets keyset.RootSecrets) (*Manager, error)
NewManager creates a new Manager instance with the provided secrets. It returns an error if no secrets are provided or if any secret is invalid.
func (Manager) NewDeletionCookie ¶
NewDeletionCookie creates a new cookie that will delete the specified cookie when sent to the client.
func (Manager) SignCookie ¶
SignCookie retrieves the value of the provided cookie, signs it, and replaces the value with the signed value. If encrypt is true, the value will be encrypted before signing.
type SignedCookie ¶
type SignedCookie[T any] struct { Manager *Manager TTL time.Duration BaseCookie BaseCookie Encrypt bool }
SignedCookie provides methods for working with signed cookies of a specific type T. If Encrypt is true, the cookie value will be encrypted before signing and decrypted after a successful verification.
func (*SignedCookie[T]) NewDeletionCookie ¶
func (sc *SignedCookie[T]) NewDeletionCookie() *http.Cookie
NewDeletionCookie creates a new cookie that will delete the current cookie when sent to the client.
func (*SignedCookie[T]) NewSignedCookie ¶
func (sc *SignedCookie[T]) NewSignedCookie(unsignedValue T, overrideBaseCookie *BaseCookie) (*http.Cookie, error)
NewSignedCookie creates a new signed cookie with the provided value and optional override settings.
func (*SignedCookie[T]) VerifyAndReadCookieValue ¶
func (sc *SignedCookie[T]) VerifyAndReadCookieValue(r *http.Request) (T, error)
VerifyAndReadCookieValue retrieves and verifies the value of the signed cookie from the request. It returns the decoded value of type T or an error if retrieval or verification fails.