Documentation
¶
Overview ¶
@Author daixk 2025/12/22 15:56:00
@Author daixk 2025/12/22 15:56:00
Index ¶
- Constants
- type Config
- type NonceManager
- func NewDefaultNonceManager(authType, prefix string, storage adapter.Storage) *NonceManager
- func NewNonceManager(authType, prefix string, storage adapter.Storage, ttl time.Duration) *NonceManager
- func NewNonceManagerWithConfig(authType, prefix string, storage adapter.Storage, cfg *Config) *NonceManager
- func (nm *NonceManager) Generate(ctx context.Context) (string, error)
- func (nm *NonceManager) GenerateWithTimeout(ctx context.Context, timeout time.Duration) (string, error)
- func (nm *NonceManager) GetTTL(ctx context.Context, nonce string) (int64, error)
- func (nm *NonceManager) IsValid(ctx context.Context, nonce string) bool
- func (nm *NonceManager) Verify(ctx context.Context, nonce string) bool
- func (nm *NonceManager) VerifyAndConsume(ctx context.Context, nonce string) error
Constants ¶
const ( // DefaultNonceTTL stores default nonce ttl DefaultNonceTTL 存储默认 nonce 过期时间 DefaultNonceTTL = 5 * time.Minute // NonceLength stores nonce byte length NonceLength 存储 Nonce 字节长度 NonceLength = 32 // NonceKeySuffix stores nonce key suffix NonceKeySuffix 存储 Nonce 键后缀 NonceKeySuffix = "nonce:" )
const ( // DefaultRefreshTTL stores default refresh ttl DefaultRefreshTTL 存储默认刷新令牌过期时间 DefaultRefreshTTL = 30 * 24 * time.Hour // DefaultAccessTTL stores default access ttl DefaultAccessTTL 存储默认访问令牌过期时间 DefaultAccessTTL = 2 * time.Hour // RefreshTokenLength stores refresh token length RefreshTokenLength 存储刷新令牌字节长度 RefreshTokenLength = 32 // RefreshKeySuffix stores refresh key suffix RefreshKeySuffix 存储刷新令牌键后缀 RefreshKeySuffix = "refresh:" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
Config defines nonce manager config Config 定义 Nonce 管理器配置
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns default nonce config DefaultConfig 返回默认 Nonce 配置
type NonceManager ¶
type NonceManager struct {
// contains filtered or unexported fields
}
NonceManager defines nonce manager NonceManager 定义 Nonce 管理器
func NewDefaultNonceManager ¶
func NewDefaultNonceManager(authType, prefix string, storage adapter.Storage) *NonceManager
NewDefaultNonceManager creates nonce manager with default config NewDefaultNonceManager 使用默认配置创建 Nonce 管理器
func NewNonceManager ¶
func NewNonceManager(authType, prefix string, storage adapter.Storage, ttl time.Duration) *NonceManager
NewNonceManager creates nonce manager NewNonceManager 创建新的 Nonce 管理器
func NewNonceManagerWithConfig ¶
func NewNonceManagerWithConfig(authType, prefix string, storage adapter.Storage, cfg *Config) *NonceManager
NewNonceManagerWithConfig creates nonce manager with config NewNonceManagerWithConfig 使用配置创建 Nonce 管理器
func (*NonceManager) Generate ¶
func (nm *NonceManager) Generate(ctx context.Context) (string, error)
Generate creates nonce with default ttl Generate 使用默认有效期生成并存储 nonce
func (*NonceManager) GenerateWithTimeout ¶
func (nm *NonceManager) GenerateWithTimeout(ctx context.Context, timeout time.Duration) (string, error)
GenerateWithTimeout creates nonce with timeout GenerateWithTimeout 使用指定有效期生成并存储 nonce
func (*NonceManager) IsValid ¶
func (nm *NonceManager) IsValid(ctx context.Context, nonce string) bool
IsValid checks nonce without consuming IsValid 检查 nonce 是否有效且不消费
func (*NonceManager) Verify ¶
func (nm *NonceManager) Verify(ctx context.Context, nonce string) bool
Verify verifies and consumes nonce Verify 验证并消费 nonce 且在不存在时返回 false
func (*NonceManager) VerifyAndConsume ¶
func (nm *NonceManager) VerifyAndConsume(ctx context.Context, nonce string) error
VerifyAndConsume verifies nonce with error VerifyAndConsume 验证并消费 nonce 且在无效时返回错误