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 GetSession(r *http.Request, cookieName string, sessionStore SessionStore) (*sessions.Session, error)
- func NewState() (string, error)
- func RemoveCookie(w http.ResponseWriter, cookieName string, v Config)
- func RemoveSession(r *http.Request, w http.ResponseWriter, cookieName string, ...) error
- func SetCookie(w http.ResponseWriter, value string, cookieName string, v Config)
- func SetCookieB64(w http.ResponseWriter, body []byte, cookieName string, v Config) string
- func SetSession(r *http.Request, w http.ResponseWriter, value, cookieName, valueName string, ...) error
- func SetSessionB64(r *http.Request, w http.ResponseWriter, body []byte, ...) (string, error)
- type Config
- type OptionsParse
- type SessionStore
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSession ¶ added in v0.2.0
func GetSession(r *http.Request, cookieName string, sessionStore SessionStore) (*sessions.Session, error)
GetSession function retrieves a session from a session store based on a cookie name and a request
func NewState ¶ added in v0.2.0
NewState generates cryptographically secure random state with base64 URL encoding
func RemoveCookie ¶
func RemoveCookie(w http.ResponseWriter, cookieName string, v Config)
RemoveCookie function removes a cookie from the HTTP response
func RemoveSession ¶ added in v0.2.0
func RemoveSession(r *http.Request, w http.ResponseWriter, cookieName string, sessionStore SessionStore) error
RemoveSession function removes a session from the session store based on the provided cookie name
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
func SetSession ¶ added in v0.2.0
func SetSession(r *http.Request, w http.ResponseWriter, value, cookieName, valueName string, sessionStore SessionStore) error
SetSession function sets a session value in a session store and also sets a corresponding cookie in the response
func SetSessionB64 ¶ added in v0.2.0
func SetSessionB64(r *http.Request, w http.ResponseWriter, body []byte, cookieName, valueName string, sessionStore SessionStore) (string, error)
SetSessionB64 function sets a base64-encoded session value in a cookie and returns the session ID
Types ¶
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 SessionStore ¶ added in v0.2.0
SessionStore interface specifies a single method `Get` that takes an `http.Request` and a string as parameters and returns a `*sessions.Session` and an error. Any type that implements this `Get` method can be considered as implementing the `SessionStore` interface
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