Documentation ¶
Index ¶
Constants ¶
View Source
const ( JWTClaimsExp = "exp" JWTClaimsSub = "sub" )
jwt claims RFC 7519 https://tools.ietf.org/html/rfc7519#section-4.1.2
View Source
const Name = "jwt"
Variables ¶
View Source
var ( ErrNoHeader = errors.New("no authorization in header") ErrInvalidAuth = errors.New("invalid authentication") )
errors
View Source
var (
ErrInvalidExp = errors.New("expire time is illegal")
)
Functions ¶
Types ¶
type Cfg ¶
type Cfg struct { ExpireAfter string SecretFunc SecretFunc //required Expire time.Duration Realm string //required //optional. Authorize check whether this request could access some resource or API based on json claims. //Typically, this method should communicate with a RBAC, ABAC system Authorize func(payload map[string]interface{}, req *http.Request) error //optional. // this function control whether a request should be validate or not // if this func is nil, validate all requests. MustAuth func(req *http.Request) bool }
type Manager ¶
type Manager interface { Sign(claims map[string]interface{}, secret interface{}, option ...Option) (string, error) Verify(tokenString string, f SecretFunc, opts ...Option) (map[string]interface{}, error) }
Manager manages token
var DefaultManager Manager = &jwtTokenManager{}
DefaultManager can be replaced
type Option ¶
type Option func(options *Options)
Option is option
func WithExpTime ¶
WithExpTime generate a token which expire after a duration for example 5s,1m,24h
func WithSigningMethod ¶
func WithSigningMethod(m SigningMethod) Option
WithSigningMethod specify the sign method
type SecretFunc ¶
type SecretFunc func(claims interface{}, method SigningMethod) (interface{}, error)
SecretFunc is a callback function to supply the key for verification. The function receives the parsed, but unverified claims in Token. This allows you to use properties in the claims of the token (such as `username`) to identify which key to use.
type SigningMethod ¶
type SigningMethod int
const ( RS256 SigningMethod = 1 RS512 SigningMethod = 2 HS256 SigningMethod = 3 )
const
Click to show internal directories.
Click to hide internal directories.