redisess

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Session

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

Session is a struct that manages session data using Redis as the backend storage.

func (*Session) Claims

func (sess *Session) Claims() security.Claims

Claims returns the security claims associated with the session. Returns: - security.Claims: The claims associated with the session.

func (*Session) Del

func (sess *Session) Del(ctx context.Context, key string) error

Del deletes a specific key from the session data in Redis. Parameters: - ctx: The context for controlling the request lifetime (context.Context). - key: The specific key to be deleted from the session data (string). Returns: - error: An error if the deletion fails.

func (*Session) Destroy

func (sess *Session) Destroy(ctx context.Context) error

Destroy deletes the session data from Redis. Parameters: - ctx: The context for controlling the request lifetime (context.Context). Returns: - error: An error if the deletion fails.

func (*Session) Get

func (sess *Session) Get(ctx context.Context, key string) mist.AnyValue

Get retrieves the value associated with a specific key from the session data in Redis. Parameters: - ctx: The context for controlling the request lifetime (context.Context). - key: The key to retrieve from the session data (string). Returns: - mist.AnyValue: The value associated with the key, or an error if the retrieval fails.

func (*Session) Set

func (sess *Session) Set(ctx context.Context, key string, val any) error

Set sets a key-value pair in the session data in Redis. Parameters: - ctx: The context for controlling the request lifetime (context.Context). - key: The key to be set in the session data (string). - val: The value to be set for the specified key (any). Returns: - error: An error if the set operation fails.

type SessionProvider

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

SessionProvider is a struct that manages session creation, token renewal, and claims update using Redis as backend storage.

func InitSessionProvider added in v0.1.11

func InitSessionProvider(client redis.Cmdable, jwtKey string) *SessionProvider

InitSessionProvider initializes and returns a new instance of SessionProvider with the given Redis client and JWT key. Parameters: - client: The Redis client used to interact with the Redis server (redis.Cmdable). - jwtKey: The key used to sign JWT tokens (string). Returns: - *SessionProvider: A pointer to a newly created SessionProvider instance.

func (*SessionProvider) Get

func (rsp *SessionProvider) Get(ctx *mist.Context) (security.Session, error)

Get retrieves the session associated with the given context or verifies the access token and returns a session based on the verified claims. Parameters: - ctx: The context for the request (*mist.Context). Returns: - security.Session: The session associated with the context. - error: An error if the session retrieval fails.

func (*SessionProvider) InitSession added in v0.1.11

func (rsp *SessionProvider) InitSession(ctx *mist.Context,
	uid int64,
	jwtData map[string]any,
	sessData map[string]any) (security.Session, error)

InitSession initializes a new session and sets initial JWT claims. Parameters: - ctx: The context for the request (*mist.Context). - uid: The user ID for the session (int64). - jwtData: JWT-related data to be included in the session (map[string]any). - sessData: Additional session data (map[string]any). Returns: - security.Session: The newly created session. - error: An error if the session creation fails.

func (*SessionProvider) RenewAccessToken

func (rsp *SessionProvider) RenewAccessToken(ctx *mist.Context) error

RenewAccessToken renews the access token using the existing refresh token stored in Redis. Parameters: - ctx: The context for the request (*mist.Context). Returns: - error: An error if the renewal fails.

func (*SessionProvider) UpdateClaims

func (rsp *SessionProvider) UpdateClaims(ctx *mist.Context, claims security.Claims) error

UpdateClaims updates the JWT claims and sets new access and refresh tokens in the response headers. Parameters: - ctx: The context for the request (*mist.Context). - claims: The claims to be updated (security.Claims). Returns: - error: An error if the update fails.

Jump to

Keyboard shortcuts

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