Documentation
¶
Index ¶
- type Session
- func (sess *Session) Claims() security.Claims
- func (sess *Session) Del(ctx context.Context, key string) error
- func (sess *Session) Destroy(ctx context.Context) error
- func (sess *Session) Get(ctx context.Context, key string) mist.AnyValue
- func (sess *Session) Set(ctx context.Context, key string, val any) error
- type SessionProvider
- func (rsp *SessionProvider) ClearToken(ctx *mist.Context) error
- func (rsp *SessionProvider) Get(ctx *mist.Context) (security.Session, error)
- func (rsp *SessionProvider) InitSession(ctx *mist.Context, userId int64, jwtData map[string]any, ...) (security.Session, error)
- func (rsp *SessionProvider) RenewAccessToken(ctx *mist.Context) error
- func (rsp *SessionProvider) UpdateClaims(ctx *mist.Context, claims security.Claims) error
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 ¶
Claims returns the security claims associated with the session. Returns: - security.Claims: The claims associated with the session.
func (*Session) Del ¶
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 ¶
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 ¶
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 ¶
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) ClearToken ¶ added in v0.1.12
func (rsp *SessionProvider) ClearToken(ctx *mist.Context) error
ClearToken is a method of the SessionProvider that clears the access and refresh tokens for a session. This method will validate the refresh token from the request, and if valid, will remove the session associated with the token from Redis and clear the token headers on the response.
Parameters:
- ctx: The mist.Context object representing the current HTTP request and response.
Returns:
- An error object if any step fails, otherwise it returns nil.
func (*SessionProvider) Get ¶
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, userId 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). - userId: 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 ¶
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.