Documentation ¶
Index ¶
- Constants
- Variables
- func Digest(content []byte) (d string)
- func FullVerify(key string)
- type ClientTye
- type HttpStorageConnector
- type HttpTokenReq
- type HttpTokenResp
- type JwtBuildOption
- type JwtPayload
- type JwtProvider
- func (jp *JwtProvider) Decode(t []byte) (ut *jwt.UnverifiedToken, err error)
- func (jp *JwtProvider) Gen(p JwtPayload) (t []byte, err error)
- func (jp *JwtProvider) GenWithTTL(p JwtPayload, ttl time.Duration) (t []byte, err error)
- func (jp *JwtProvider) Verify(t []byte) (verifiedToken *jwt.VerifiedToken, err error)
- type Option
- type Payload
- type Storage
Constants ¶
View Source
const (
JwtTokenPrefix = "jwt_"
)
Variables ¶
View Source
var (
ErrInvalid = errors.New("invalid token")
)
View Source
var WithAlg = func(alg string) JwtBuildOption { return func(provider *JwtProvider) { for _, a := range jwtAllAlg { if a.Name() == alg { provider.alg = a break } } } }
View Source
var WithDefaultTTL = func(ttl time.Duration) JwtBuildOption { return func(provider *JwtProvider) { provider.defaultTTL = ttl } }
WithDefaultTTL 设置ttl
View Source
var WithIssuer = func(issuer string) JwtBuildOption { return func(provider *JwtProvider) { provider.issuer = issuer provider.checkIssuer = true } }
WithIssuer 设置issuer, 如不设置,将不能创建jwt, 校验的时候不会检查issuer是否相同
View Source
var WithKey = func(signKey interface{}, verifyKey interface{}) JwtBuildOption { return func(provider *JwtProvider) { provider.signKey = signKey provider.verifyKey = verifyKey } }
WithKey 设置秘钥
Functions ¶
func FullVerify ¶
func FullVerify(key string)
Types ¶
type HttpStorageConnector ¶
type HttpStorageConnector struct {
Server string // 全路径 包含schema
}
type HttpTokenReq ¶
type HttpTokenReq struct {
Token string `json:"token,omitempty"`
}
type HttpTokenResp ¶
type HttpTokenResp struct {
Valid bool `json:"valid,omitempty"`
}
type JwtBuildOption ¶
type JwtBuildOption func(provider *JwtProvider)
type JwtPayload ¶
type JwtPayload struct { Org string `json:"org,omitempty"` Dept string `json:"dept,omitempty"` Uid string `json:"uid,omitempty"` Client string `json:"client,omitempty"` Scope string `json:"scope,omitempty"` // 逗号分隔a,b,c,d,..... }
func (*JwtPayload) WithClient ¶
func (jp *JwtPayload) WithClient(clientType ClientTye) *JwtPayload
type JwtProvider ¶
type JwtProvider struct {
// contains filtered or unexported fields
}
func NewJwtProvider ¶
func NewJwtProvider(options ...JwtBuildOption) (jp *JwtProvider)
func (*JwtProvider) Decode ¶
func (jp *JwtProvider) Decode(t []byte) (ut *jwt.UnverifiedToken, err error)
func (*JwtProvider) Gen ¶
func (jp *JwtProvider) Gen(p JwtPayload) (t []byte, err error)
func (*JwtProvider) GenWithTTL ¶
func (jp *JwtProvider) GenWithTTL(p JwtPayload, ttl time.Duration) (t []byte, err error)
func (*JwtProvider) Verify ¶
func (jp *JwtProvider) Verify(t []byte) (verifiedToken *jwt.VerifiedToken, err error)
type Storage ¶
type Storage interface {
Verify(key string) (p JwtPayload, err error)
}
Storage 本地token存储。不负责创建token
func NewHttpStorage ¶
func NewHttpStorage(c HttpStorageConnector) (s Storage)
func NewLocalStorage ¶
func NewLocalStorage(provider *JwtProvider) (s Storage)
func NewRedisStorage ¶
Click to show internal directories.
Click to hide internal directories.