Documentation
¶
Index ¶
- func WithDecryptKey(decryptKey string) option.Option[Options]
- func WithGenIDFunc(fn func() string) option.Option[Options]
- func WithIssuer(issuer string) option.Option[Options]
- func WithMethod(method jwt.SigningMethod) option.Option[Options]
- func WithNowFunc[T any](nowFunc func() time.Time) option.Option[Management[T]]
- type Management
- type Manager
- type Options
- type RegisteredClaims
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithDecryptKey ¶
WithDecryptKey 设置解密密钥.
func WithGenIDFunc ¶
WithGenIDFunc 设置生成 JWT ID 的函数. 可以设置成 WithGenIDFunc(uuid.NewString).
func WithMethod ¶
WithMethod 设置 JWT 的签名方法.
func WithNowFunc ¶
WithNowFunc 设置当前时间. 一般用于测试固定 jwt.
Types ¶
type Management ¶
type Management[T any] struct { // contains filtered or unexported fields }
func NewManagement ¶
func NewManagement[T any](accessJWTOptions Options, opts ...option.Option[Management[T]]) *Management[T]
NewManagement 定义一个 Management. allowTokenHeader: 默认使用 authorization 为认证请求头. exposeAccessHeader: 默认使用 x-access-token 为暴露外部的资源请求头. exposeRefreshHeader: 默认使用 x-refresh-token 为暴露外部的刷新请求头. refreshJWTOptions: 默认使用 nil 为刷新 token 的配置, 如要使用 refresh 相关功能则需要使用 WithRefreshJWTOptions 添加相关配置. rotateRefreshToken: 默认不轮换刷新令牌. 该配置需要设置 refreshJWTOptions 才有效.
func (*Management[T]) GenerateAccessToken ¶
func (m *Management[T]) GenerateAccessToken(data T) (string, error)
GenerateAccessToken 生成资源 token.
func (*Management[T]) VerifyAccessToken ¶
func (m *Management[T]) VerifyAccessToken(token string, opts ...jwt.ParserOption) (RegisteredClaims[T], error)
VerifyAccessToken 校验资源 token.
type Manager ¶
type Manager[T any] interface { // GenerateAccessToken 生成资源 token. GenerateAccessToken(data T) (string, error) // VerifyAccessToken 校验资源 token. VerifyAccessToken(token string, opts ...jwt.ParserOption) (RegisteredClaims[T], error) }
Manager jwt 管理器.
type Options ¶
type RegisteredClaims ¶
type RegisteredClaims[T any] struct { Data T `json:"data"` jwt.RegisteredClaims }
Click to show internal directories.
Click to hide internal directories.