Documentation ¶
Index ¶
- Constants
- func CookieSameSite(ss string) http.SameSite
- func NewCookie(opts CookieParams) *http.Cookie
- func NewSimpleCookie(name, value string) *http.Cookie
- type Claims
- type CookieFactory
- func (f CookieFactory) ExpireCookie(c *http.Cookie) *http.Cookie
- func (f CookieFactory) GetCookie(r *http.Request, name string) (*http.Cookie, error)
- func (f CookieFactory) GetOpts() CookieParams
- func (f CookieFactory) NewCookie(name, value string) *http.Cookie
- func (f CookieFactory) SetCookie(w http.ResponseWriter, c *http.Cookie)
- type CookieMaker
- type CookieParams
- type RegisteredClaims
- type Serializer
- type Session
- type SessionHandler
- type TokenSigner
Constants ¶
const ( HS256 = iota HS384 HS512 ES256 ES384 ES512 EdDSA RS256 RS384 RS512 PS256 PS384 PS512 )
These represent the method of signing the JWT.
Variables ¶
This section is empty.
Functions ¶
func CookieSameSite ¶ added in v0.1.1
CookieSameSite takes a string value and return an http.SameSite
func NewCookie ¶
func NewCookie(opts CookieParams) *http.Cookie
NewCookie creates a new Cookie. Keep in mind that using a non-secure cookie will not overwrite a secure cookie
func NewSimpleCookie ¶
NewSimpleCookie creates a secure, HTTP-only cookie for the TLD that expires in 30 min.
Types ¶
type CookieFactory ¶
type CookieFactory struct {
Opts CookieParams
}
Factory is a set of params used to create cookies.
func NewCookieFactory ¶
func NewCookieFactory(opts CookieParams) CookieFactory
NewCookieFactory creates a new Factory with the given options.
func (CookieFactory) ExpireCookie ¶
func (f CookieFactory) ExpireCookie(c *http.Cookie) *http.Cookie
ExpireCookie returns the http cookie having set it's expiration. This cookie must still be sent to the browser.
func (CookieFactory) GetOpts ¶
func (f CookieFactory) GetOpts() CookieParams
GetOpts allows visibility to the underlying options of a Cookie.
func (CookieFactory) NewCookie ¶
func (f CookieFactory) NewCookie(name, value string) *http.Cookie
NewCookie creates a cookie with the given name and value and CookieFactory's options.
func (CookieFactory) SetCookie ¶
func (f CookieFactory) SetCookie(w http.ResponseWriter, c *http.Cookie)
SetCookie essentially "saves" the cookie by adding it to the request.
type CookieMaker ¶
type CookieMaker interface { GetCookie(r *http.Request, name string) (*http.Cookie, error) ExpireCookie(c *http.Cookie) *http.Cookie NewCookie(name, value string) *http.Cookie SetCookie(w http.ResponseWriter, c *http.Cookie) GetOpts() CookieParams }
CookieFactory is an interface for our Cookie Factory
type CookieParams ¶
type CookieParams struct { Name string Value string TTL int Path string Domain string IsSecure bool HTTPOnly bool SameSite http.SameSite }
CookieParams represents the various bits of information that make up a cookie.
type RegisteredClaims ¶
type RegisteredClaims = jwt.RegisteredClaims
RegisteredClaims is an alias that avoids asking implimntors to import the parent JWT lib.
type Serializer ¶
type Serializer interface { Serialize(claims Claims) (string, error) Unserialize(jwt string, dest Claims) error }
Serializer is some API sugar to simplify making and reading JWTs.
type Session ¶
type Session struct {
RegisteredClaims
}
Session wraps the set of claims in a couple of sugary methods
func (*Session) Active ¶
Active checks to see if the claims' `nbf` field is less than the given time
func (*Session) IsExpired ¶
IsExpired checks to see if the claims' `exp` field is less than the given time
type SessionHandler ¶
type SessionHandler struct {
// contains filtered or unexported fields
}
SessionHandler manages an http session cookie of a given name
func NewSessionHandler ¶
func NewSessionHandler( name string, factory CookieFactory, serializer Serializer, ) *SessionHandler
NewSessionHandler returns a session handler tied to a given name and equipped to sign the token and set the cookie
func (*SessionHandler) DeleteSession ¶
func (h *SessionHandler) DeleteSession(w http.ResponseWriter) error
DeleteSession replaces the session with one that is expired and sets the cookie to expired
func (*SessionHandler) GetSession ¶
GetSession retrieves the named session from the http request
func (*SessionHandler) SaveSession ¶
func (h *SessionHandler) SaveSession(w http.ResponseWriter, session *Session) error
SaveSession sets the named session in the http request
type TokenSigner ¶
type TokenSigner struct { Method jwt.SigningMethod Key interface{} }
TokenSigner combines signing and serializing a JWT by holding the signing method and implementing the Serializer interface.
func NewSigner ¶
func NewSigner(m int, key interface{}) *TokenSigner
NewSigner returns a TokenSigner assigned the given method
func (*TokenSigner) Serialize ¶
func (s *TokenSigner) Serialize(claims Claims) (string, error)
Serialize takes a set of Claims and returns a signed & encoded JWT.
func (*TokenSigner) Unserialize ¶
func (s *TokenSigner) Unserialize(json string, dest Claims) error
Unserialize takes a signed & encoded JWT and sets the claims within the destination.