Documentation
¶
Index ¶
- Constants
- Variables
- func Module(opts ...di.Node) di.Node
- func SetPrincipalLocals(c fiber.Ctx, principal *Principal)
- func UseCachedLookup(opts ...CacheOption) di.Node
- func UseCachedRevoker() di.Node
- func UseCachedRotator() di.Node
- func UseHasher(hasher Hasher) di.Node
- func UseLookup(lookup KeyLookup) di.Node
- func UseRevoker(revoker Revoker) di.Node
- func UseRotator(rotator Rotator) di.Node
- func UseUsageRecorder(recorder KeyUsageRecorder) di.Node
- func WithPrincipal(ctx context.Context, principal *Principal) context.Context
- type Argon2idHasher
- type CacheOption
- type CachedLookup
- type CachedLookupConfig
- type CachedRevoker
- type CachedRotator
- type Config
- type Generator
- type HMACSHA256Hasher
- type Hasher
- type IssuedKey
- type KeyGenerator
- type KeyLookup
- type KeyUsageRecorder
- type LookupInvalidator
- type Manager
- type NewServiceParams
- type Principal
- type Revoker
- type Rotator
- type SaltedSHA256Hasher
- type Service
- func (s *Service) IssueKey(appID string, prefix string, scopes []string, metadata map[string]string, ...) (*IssuedKey, error)
- func (s *Service) Middleware() fiber.Handler
- func (s *Service) RevokeKey(ctx context.Context, keyID string, reason string) error
- func (s *Service) RotateKey(ctx context.Context, keyID string, prefix string) (*IssuedKey, error)
- func (s *Service) ValidateRawKey(ctx context.Context, rawKey string) (*Principal, error)
- type StoredKey
Constants ¶
View Source
const ( HasherArgon2id = "argon2id" HasherHMACSHA256 = "hmac-sha256" )
View Source
const PrincipalTypeAPIKey = "apikey"
Variables ¶
View Source
var ( ErrLookupNotConfigured = errors.New("apikey: key lookup is not configured") ErrRevokerNotConfigured = errors.New("apikey: revoker is not configured") ErrRotatorNotConfigured = errors.New("apikey: rotator is not configured") ErrInvalidAPIKey = errors.New("apikey: invalid api key") ErrRevokedAPIKey = errors.New("apikey: api key revoked") ErrExpiredAPIKey = errors.New("apikey: api key expired") )
View Source
var (
ErrInvalidHashFormat = errors.New("apikey: invalid hash format")
)
View Source
var (
ErrInvalidRawKeyFormat = errors.New("apikey: invalid raw key format")
)
Functions ¶
func SetPrincipalLocals ¶
func UseCachedLookup ¶
func UseCachedLookup(opts ...CacheOption) di.Node
func UseCachedRevoker ¶
func UseCachedRotator ¶
func UseRevoker ¶
func UseRotator ¶
func UseUsageRecorder ¶
func UseUsageRecorder(recorder KeyUsageRecorder) di.Node
Types ¶
type Argon2idHasher ¶
type Argon2idHasher struct {
// contains filtered or unexported fields
}
Hash format: a1$memory$time$threads$base64(salt)$base64(hash)
func NewArgon2idHasher ¶
func NewArgon2idHasher() *Argon2idHasher
type CacheOption ¶
type CacheOption func(*CachedLookupConfig)
func WithCacheL1TTL ¶
func WithCacheL1TTL(ttlSec int) CacheOption
func WithCacheL2TTL ¶
func WithCacheL2TTL(ttlSec int) CacheOption
func WithCacheNamespace ¶
func WithCacheNamespace(namespace string) CacheOption
func WithCacheNegativeTTL ¶
func WithCacheNegativeTTL(ttlSec int) CacheOption
func WithCacheRedisKeyPrefix ¶
func WithCacheRedisKeyPrefix(prefix string) CacheOption
type CachedLookup ¶
type CachedLookup struct {
// contains filtered or unexported fields
}
func NewCachedLookup ¶
func NewCachedLookup(base KeyLookup, redisClient rd.RedisClient, cfg CachedLookupConfig) *CachedLookup
func (*CachedLookup) FindByKeyID ¶
func (*CachedLookup) InvalidateKey ¶
func (c *CachedLookup) InvalidateKey(ctx context.Context, keyID string) error
type CachedLookupConfig ¶
type CachedRevoker ¶
type CachedRevoker struct {
// contains filtered or unexported fields
}
func NewCachedRevoker ¶
func NewCachedRevoker(base Revoker, invalidator LookupInvalidator) *CachedRevoker
type CachedRotator ¶
type CachedRotator struct {
// contains filtered or unexported fields
}
func NewCachedRotator ¶
func NewCachedRotator(base Rotator, invalidator LookupInvalidator) *CachedRotator
type Config ¶
type Config struct {
HeaderName string `mapstructure:"header_name"`
HeaderScheme string `mapstructure:"header_scheme"`
HasherMode string `mapstructure:"hasher_mode"`
HMACSecret string `mapstructure:"hmac_secret"`
KeyPrefix string `mapstructure:"key_prefix"`
KeyIDLength int `mapstructure:"key_id_length"`
SecretLength int `mapstructure:"secret_length"`
SkewAllowance time.Duration `mapstructure:"skew_allowance"`
SetPrincipalCtx bool `mapstructure:"set_principal_ctx"`
SetPrincipalBody bool `mapstructure:"set_principal_body"`
DetailedErrors bool `mapstructure:"detailed_errors"`
}
type HMACSHA256Hasher ¶
type HMACSHA256Hasher struct {
// contains filtered or unexported fields
}
func NewHMACSHA256Hasher ¶
func NewHMACSHA256Hasher(secret string) (*HMACSHA256Hasher, error)
type Hasher ¶
type Hasher interface {
Hash(secret string) (string, error)
Verify(hash string, secret string) (bool, error)
}
func NewHasherFromConfig ¶
type IssuedKey ¶
type IssuedKey struct {
KeyID string `json:"key_id"`
AppID string `json:"app_id"`
RawKey string `json:"raw_key"`
Prefix string `json:"prefix"`
SecretHash string `json:"-"`
Scopes []string `json:"scopes"`
Metadata map[string]string `json:"metadata,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}
type KeyGenerator ¶
type KeyGenerator struct {
// contains filtered or unexported fields
}
func NewKeyGenerator ¶
func NewKeyGenerator(cfg Config) *KeyGenerator
func (*KeyGenerator) GenerateRawKey ¶
func (*KeyGenerator) ParseRawKey ¶
func (g *KeyGenerator) ParseRawKey(rawKey string) (keyID string, secret string, err error)
type KeyUsageRecorder ¶
type LookupInvalidator ¶
type Manager ¶
type Manager interface {
IssueKey(appID string, prefix string, scopes []string, metadata map[string]string, expiresAt *time.Time) (*IssuedKey, error)
ValidateRawKey(ctx context.Context, rawKey string) (*Principal, error)
Middleware() fiber.Handler
RevokeKey(ctx context.Context, keyID string, reason string) error
RotateKey(ctx context.Context, keyID string, prefix string) (*IssuedKey, error)
}
type NewServiceParams ¶
type Principal ¶
type SaltedSHA256Hasher ¶
type SaltedSHA256Hasher struct{}
Hash format: v1$base64(salt)$base64(sha256(salt || secret))
func NewSaltedSHA256Hasher ¶
func NewSaltedSHA256Hasher() *SaltedSHA256Hasher
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(p NewServiceParams) *Service
func (*Service) Middleware ¶
Click to show internal directories.
Click to hide internal directories.