Documentation
¶
Index ¶
Constants ¶
View Source
const (
ErrNoAuthHeader = oerrs.String("missing Authorization: Bearer header is not set")
)
errors
View Source
const (
// TokenContextKey is the key used to access the saved token inside an gserv.Context.
TokenContextKey = ":JTK:"
)
Variables ¶
View Source
var ( SecureHeaders = SHM{ "X-Frame-Options": "SAMEORIGIN", "X-XSS-Protection": "1; mode=block", "X-Download-Options": "noopen", "Content-Security-Policy": "default-src https:", } // https://googleblog.blogspot.com/2007/07/robots-exclusion-protocol-now-with-even.html NoIndexing = SHM{ "X-Robots-Tag": "noindex", } // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security HSTS = SHM{ "Strict-Transport-Security": "max-age=15552000; includeSubDomains", } // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security HSTSPreload = SHM{ "Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload", } )
SimpleHeadersMaps of common headers based on https://rorsecurity.info/portfolio/new-http-headers-for-more-security
View Source
var DefaultAuth = &Auth{ SigningMethod: jwt.SigningMethodHS256, Extractor: *jwtReq.OAuth2Extractor, NewClaims: func() jwt.Claims { return jwt.MapClaims{} }, }
DefaultAuth has the default values for Auth
View Source
var DefaultParser = &jwt.Parser{ UseJSONNumber: true, }
Functions ¶
func ApplyHeaders ¶
ApplyHeaders is a middle to apply a static set of headers to an gserv.Context
Types ¶
type Auth ¶
type Auth struct { SigningMethod jwt.SigningMethod Extractor jwtReq.MultiExtractor NewClaims func() jwt.Claims // TokenKey is used inside the CheckAuth middleware. CheckToken TokenKeyFunc // AuthKeyFunc is used inside the SignIn middleware. AuthToken TokenKeyFunc CookieHost string AuthCookies []string CookieHTTPS bool }
Auth is a simple handler for authorization using JWT with a simple
func NewAuth ¶
func NewAuth(checkTokenFn TokenKeyFunc, authKeyFunc TokenKeyFunc, extractors ...jwtReq.Extractor) (a *Auth)
NewAuth returns a new Auth struct with the given keyForUser and the defaults from DefaultAuth
type CookieExtractor ¶
type CookieExtractor []string
CookieExtractor implements an Extractor to use auth token from cookies
func (CookieExtractor) ExtractToken ¶
func (e CookieExtractor) ExtractToken(req *http.Request) (string, error)
type SHM ¶
SHM is a Simple Headers Map
type StandardClaims ¶
type StandardClaims = jwt.StandardClaims
StandardClaims is an alias for jwt.StandardClaims
Click to show internal directories.
Click to hide internal directories.