Documentation
¶
Overview ¶
Package security is a toolkit for security check and authorization
Package security is a toolkit for security check and authorization
Index ¶
Constants ¶
View Source
const ( ErrInvalidToken = errors.String("invalid token") ErrNotFound = errors.String("not found") )
View Source
const (
TokenNamespace = "security:jwt:token"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Claims ¶
type Claims struct {
ID string `json:"jti,omitempty"`
Issuer string `json:"iss,omitempty"`
Subject string `json:"sub,omitempty"`
Audience []string `json:"aud,omitempty"`
ExpiresAt int64 `json:"exp,omitempty"`
NotBefore int64 `json:"nbf,omitempty"`
IssuedAt int64 `json:"iat,omitempty"`
Custom map[string]interface{} `json:"custom,omitempty"`
}
Claims defines basic Token claims
type Security ¶ added in v0.0.20
type Security interface {
// GenerateToken Generate a JWT (JSON Web HeaderToken) with the provided subject.
GenerateToken(ctx context.Context, subject string) (Token, error)
// ValidateAccess Validate if a token is valid.
ValidateAccess(ctx context.Context, tokenStr string) error
// DestroyToken Invalidate a token by removing it from the token store.
DestroyToken(ctx context.Context, tokenStr string) error
// ParseSubject Parse the subject (or user identifier) from a given access token.
ParseSubject(ctx context.Context, tokenStr string) (string, error)
// Release any resources held by the authorize instance.
Release(ctx context.Context) error
}
func NewSecurity ¶ added in v0.0.42
func NewSecurity(serializer TokenSerializer, ss ...Setting) Security
type Setting ¶ added in v0.0.42
type Setting = func(s *security)
func WithStorage ¶ added in v0.0.42
func WithStorage(store TokenStorage) Setting
type StorageOption ¶ added in v0.0.42
StorageOption contains options for the JWT datacache
type StorageSetting ¶
type StorageSetting = func(*StorageOption)
func WithCache ¶
func WithCache(c cache.Cache) StorageSetting
func WithNamespace ¶ added in v0.0.42
func WithNamespace(ns string) StorageSetting
type Token ¶ added in v0.0.38
type Token struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
Expiry time.Time `json:"expiry,omitempty"`
ExpiresIn int64 `json:"expires_in,omitempty"`
Claims *Claims `json:"-"`
}
Token is an interface for getting token information
type TokenSerializer ¶ added in v0.0.38
type TokenStorage ¶ added in v0.0.42
type TokenStorage interface {
// Set stores the token with a specific expiration time
Set(ctx context.Context, tokenStr string, expiration time.Duration) error
// Delete deletes the token from the tokenStorage
Delete(ctx context.Context, tokenStr string) error
// Validate checks if the token exists in the tokenStorage
Validate(ctx context.Context, tokenStr string) error
// Close closes the tokenStorage
Close(ctx context.Context) error
}
TokenStorage is the interface that tokenStorage the token.
func NewTokenStorage ¶ added in v0.0.42
func NewTokenStorage(ss ...StorageSetting) TokenStorage
NewTokenStorage creates a new TokenStorage with a Cache and optional StoreOptions
Click to show internal directories.
Click to hide internal directories.