sessions

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// USER_SESSION_NAME is the name of the cookie containing the user session id
	USER_SESSION_NAME = common.APP_NAME_SHORT + "-ui-user"
	// SESSION_KEY_SESSION_INFO is the key used to store the session struct in the session store
	SESSION_KEY_SESSION_INFO = "session-info"
)

Variables

This section is empty.

Functions

func IsLoggedIn

func IsLoggedIn(r *http.Request) bool

IsLoggedIn checks if the user has logged in already

func SaveSession

func SaveSession(w http.ResponseWriter, r *http.Request, sessInfo Session) error

SaveSession updates the info of an existing session.

func SetupSessionStore

func SetupSessionStore() error

SetupSessionStore sets up the session store.

Types

type Session

type Session struct {
	Id                    string         `json:"id"`
	Tokens                types.Tokens   `json:"tokens"`
	User                  types.UserInfo `json:"user"`
	PostLoginRedirectPath string         `json:"post_login_redirect_path"`
}

Session contains data for a user session

func GetSession

func GetSession(r *http.Request) (Session, error)

GetSession returns info about the session. It returns error if the session doesn't exist.

func NewSession

func NewSession(w http.ResponseWriter, r *http.Request) (Session, error)

NewSession creates a new session.

func (Session) GetCSRFToken

func (session Session) GetCSRFToken() string

GetCSRFToken returns a random string to use as the CSRF token based on the session

func (Session) IsValidCSRFToken

func (session Session) IsValidCSRFToken(actualCSRFToken string) bool

IsValidCSRFToken checks the provided access token against the CSRF token generated from the session

func (*Session) RefreshUserTokensIfExpired

func (session *Session) RefreshUserTokensIfExpired() bool

RefreshUserTokensIfExpired refreshs the user token if it has expired

Jump to

Keyboard shortcuts

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