Documentation
¶
Overview ¶
Package jwt 身份认证
Index ¶
Constants ¶
View Source
const ( // AuthJwtCtxKey context key AuthJwtCtxKey = ContextKey("AuthJwtCtxKey") )
Variables ¶
View Source
var DefaultParseTokenFunc = func(ctx context.Context, req interface{}) (string, error) { head := trpcHttp.Head(ctx) token := head.Request.Header.Get("Authorization") return strings.TrimPrefix(token, "Bearer "), nil }
DefaultParseTokenFunc 默认获取 token 的函数, 用户可自定义实现
View Source
var ( // ErrInvalidToken 非法 token ErrInvalidToken = fmt.Errorf("invalid token") )
Functions ¶
func GetCustomInfo ¶
GetCustomInfo 获取用户信息 (参数 ptr 为struct的指针对象)
func ServerFilter ¶
func ServerFilter(opts ...Option) filter.ServerFilter
ServerFilter 设置服务端增加 jwt 验证
Types ¶
type Config ¶
type Config struct { Secret string `yaml:"secret"` // 签名使用的私钥 Expired int `yaml:"expired"` // 过期时间 seconds Issuer string `yaml:"issuer"` // 发行人 ExcludePaths []string `yaml:"exclude_paths"` // 跳过 jwt 鉴权的 paths, 如登陆接口 }
Config 插件配置
type Option ¶
type Option func(*options)
Option 设置参数选项
func WithExcludePathSet ¶
WithExcludePathSet 设置 path 白名单
Click to show internal directories.
Click to hide internal directories.