mongostore

package
v0.0.0-...-9b5cd94 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

mongostore contains gorilla session store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoStore

type MongoStore struct {
	Codecs  []securecookie.Codec
	Options *sessions.Options // default configuration
	// contains filtered or unexported fields
}

MongoStore stores sessions in mongo db.

func NewStore

func NewStore(client mongo.DbClient, keyPairs ...[]byte) *MongoStore

NewStore creates new mongo store.

The client argument is the mongo db client where sessions will be saved.

Keys are defined in pairs to allow key rotation, but the common case is to set a single authentication key and optionally an encryption key.

The first key in a pair is used for authentication and the second for encryption. The encryption key can be set to nil or omitted in the last pair, but the authentication key is required in all pairs.

It is recommended to use an authentication key with 32 or 64 bytes. The encryption key, if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.

func (*MongoStore) ExpireSessions

func (s *MongoStore) ExpireSessions(ctx context.Context, user string, provider string) error

func (*MongoStore) ExpireSessionsByUserIDs

func (s *MongoStore) ExpireSessionsByUserIDs(ctx context.Context, ids []string) error

func (*MongoStore) Get

func (s *MongoStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get returns a session for the given name after adding it to the registry.

It returns a new session if the sessions doesn't exist. Access IsNew on the session to check if it is an existing session or a new one.

It returns a new session and an error if the session exists but could not be decoded.

func (*MongoStore) GetActiveSessionsCount

func (s *MongoStore) GetActiveSessionsCount(ctx context.Context) (int64, error)

func (*MongoStore) New

func (s *MongoStore) New(r *http.Request, name string) (*sessions.Session, error)

New returns a session for the given name without adding it to the registry.

The difference between New() and Get() is that calling New() twice will decode the session data twice, while Get() registers and reuses the same decoded session after the first call.

func (*MongoStore) Save

func (s *MongoStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save adds a single session to the response.

If the Options.MaxAge of the session is <= 0 then the session file will be deleted from the store path. With this process it enforces the properly session cookie handling so no need to trust in the cookie management in the web browser.

func (*MongoStore) StartAutoClean

func (s *MongoStore) StartAutoClean(ctx context.Context, timeout time.Duration)

Jump to

Keyboard shortcuts

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