Documentation ¶
Index ¶
Constants ¶
View Source
const ( JWTClaimsExp = "exp" JWTClaimsSub = "sub" )
jwt claims RFC 7519 https://tools.ietf.org/html/rfc7519#section-4.1.2
Variables ¶
View Source
var (
ErrInvalidExp = errors.New("expire time is illegal")
)
token pkg common errors
Functions ¶
Types ¶
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.