Documentation
¶
Overview ¶
Package store is for storing cookies, sessions, and maybe other fun stuff
Index ¶
- func GetCookie(r *http.Request, cookieName string) (*http.Cookie, error)
- func RemoveCookie(w http.ResponseWriter, cookieName string, v Config)
- func SetCookie(w http.ResponseWriter, value string, cookieName string, v Config)
- func SetCookieB64(w http.ResponseWriter, body []byte, cookieName string, v Config) string
- type AuthSession
- func (sess *AuthSession) DeleteSession(ctx context.Context, sessionID string) error
- func (sess *AuthSession) GetExpiryFromSession(ctx context.Context, sessionID string) (time.Time, error)
- func (sess *AuthSession) GetUserIDFromSession(ctx context.Context, sessionID string) (string, error)
- func (sess *AuthSession) StoreSession(ctx context.Context, sessionID string, userID *ent.User) error
- type AuthSessions
- type Config
- type OptionsParse
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RemoveCookie ¶
func RemoveCookie(w http.ResponseWriter, cookieName string, v Config)
RemoveCookie function removes a cookie from the HTTP response
func SetCookie ¶
func SetCookie(w http.ResponseWriter, value string, cookieName string, v Config)
SetCookie function sets a cookie with the given value and name
func SetCookieB64 ¶
SetCookieB64 function sets a base64-encoded cookie with the given name and value in the HTTP response
Types ¶
type AuthSession ¶
type AuthSession struct {
// contains filtered or unexported fields
}
AuthSession has a single field `client` of type `*ent.Client`, which is a client for interacting with the database.
func (*AuthSession) DeleteSession ¶
func (sess *AuthSession) DeleteSession(ctx context.Context, sessionID string) error
DeleteSession is used to delete a session from the database
func (*AuthSession) GetExpiryFromSession ¶
func (sess *AuthSession) GetExpiryFromSession(ctx context.Context, sessionID string) (time.Time, error)
GetExpiryFromSession is used to retrieve the expiration time of a session from the database
func (*AuthSession) GetUserIDFromSession ¶
func (sess *AuthSession) GetUserIDFromSession(ctx context.Context, sessionID string) (string, error)
GetUserIDFromSession is used to retrieve the user ID associated with a session from the database
func (*AuthSession) StoreSession ¶
func (sess *AuthSession) StoreSession(ctx context.Context, sessionID string, userID *ent.User) error
StoreSession is used to store a session in the database
type AuthSessions ¶
type AuthSessions interface {
StoreSession(ctx context.Context, sessionID string, userID *ent.User) error
GetUserIDFromSession(ctx context.Context, sessionID string) (string, error)
DeleteSession(ctx context.Context, sessionID string) error
GetExpiryFromSession(ctx context.Context, sessionID string) (time.Time, error)
}
AuthSessions is defining an interface named AuthSessions
func NewAuthSession ¶
func NewAuthSession(c *ent.Client) AuthSessions
NewAuthSession function creates a new instance of the AuthSessions struct
type Config ¶
type Config struct {
// Domain for defines the host to which the cookie will be sent.
Domain string `cfg:"domain"`
// Path that must exist in the requested URL for the browser to send the Cookie header.
Path string `cfg:"path"`
// MaxAge the number of seconds until the cookie expires.
MaxAge int `cfg:"max_age"`
// Secure to cookie only sent over HTTPS.
Secure bool `cfg:"secure"`
// SameSite for Lax 2, Strict 3, None 4.
SameSite http.SameSite `cfg:"same_site"`
// HttpOnly for true for not accessible by JavaScript.
HttpOnly bool `cfg:"http_only"` //nolint:stylecheck
}
Config is used to store configuration settings for setting and removing cookies
type OptionsParse ¶
type OptionsParse func(*optionsParse)
OptionsParse allows the `Parse` function to accept optional parameters by providing a way to customize its behavior
func WithBase64 ¶
func WithBase64(v bool) OptionsParse
type Token ¶
type Token struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
RefreshExpiresIn int `json:"refresh_expires_in"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
NotBeforePolicy int `json:"not-before-policy"`
SessionState string `json:"session_state"`
Scope string `json:"scope"`
IDToken string `json:"id_token"`
}
Token represents a token object