Documentation ¶
Index ¶
Constants ¶
const TokenManagerKey middlewareKey = 1
TokenManagerKey is the JWT middleware key used to store the token manager in the context.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyFunc ¶
type KeyFunc func() (interface{}, error)
KeyFunc is a function that returns the key to sign a token. It should return a []byte (for all) or a *rsa.PrivateKey or *ecdsa.PrivateKey
type SigningMethod ¶
type SigningMethod int
SigningMethod is the enum that lists the supported token signature hashing algorithms.
const ( // RSA256 signing algorithm RSA256 SigningMethod = iota + 1 // RSA384 signing algorithm RSA384 // RSA512 signing algorithm RSA512 // HMAC256 signing algorithm HMAC256 // HMAC384 signing algorithm HMAC384 // HMAC512 signing algorithm HMAC512 // ECDSA256 signing algorithm ECDSA256 // ECDSA384 signing algorithm ECDSA384 // ECDSA512 signing algorithm ECDSA512 )
type Specification ¶
type Specification struct { // TokenHeader is the HTTP header to search for the JWT Token // Defaults to "Authorization" TokenHeader string // TokenParam is the request parameter to parse for the JWT Token // Defaults to "token" TokenParam string // AllowParam is a flag that determines whether it is allowable // to parse tokens from the querystring // Defaults to false AllowParam bool // ValidationFunc is a function that returns the key to validate the JWT // Required, no default ValidationFunc ValidationKeyfunc // AuthOptions is a flag that determines whether a token is required on OPTIONS // requests AuthOptions bool // TTLMinutes is the TTL for tokens that are generated TTLMinutes int // RefreshTTLMinutes is the TTL for refresh tokens that are generated // and should generally be much longer than TTLMinutes RefreshTTLMinutes int // Issuer is the name of the issuer that will be inserted into the // generated token's claims Issuer string // KeySigningMethod determines the type of key that will be used to sign // Tokens. KeySigningMethod SigningMethod // SigningKeyFunc is a function that returns the key used to sign the token SigningKeyFunc KeyFunc // CommonClaims is a list of claims added to all tokens issued CommonClaims map[string]interface{} }
Specification describes the JWT authorization properties. It is used to both instantiate a middleware and a token manager. The middleware uses the specification properties to authorize the incoming request while the token manager uses it to create authorization tokens.
type TokenManager ¶
type TokenManager struct {
// contains filtered or unexported fields
}
TokenManager provides for the creation of access and refresh JWT Tokens
func NewTokenManager ¶
func NewTokenManager(spec *Specification) *TokenManager
NewTokenManager returns a TokenManager. If TTLMinutes isn't specified it will default to 5 minutes. Use the same Specification as you use for Middleware() to ensure your tokens are compatible.
type ValidationKeyfunc ¶
ValidationKeyfunc is a function that takes a token and returns the key to validate that token, which allows it to use inforamtion from the key itself to choose the key to return.