Documentation
¶
Overview ¶
Package security implements the functions, types, and interfaces for the module.
Package security implements the functions, types, and interfaces for the module.
Package security implements the functions, types, and interfaces for the module.
Package security is a toolkit for security check and authorization ¶
Package security implements the functions, types, and interfaces for the module.
Package security provides interfaces and types for security-related operations ¶
Package security is a toolkit for security check and authorization ¶
Package security implements the functions, types, and interfaces for the module.
Index ¶
- Constants
- func FromToken(ctx context.Context) string
- func NewSecurityCache() cache.Cache
- func NewToken(ctx context.Context, token string) context.Context
- type Authenticator
- type Authorizer
- type Claims
- type Policy
- type PolicyChecker
- type PolicyManager
- type Scheme
- type Serializer
- type StorageOption
- type StorageSetting
- type TokenStorage
- type TokenType
- type UnimplementedClaims
- func (u UnimplementedClaims) GetAudience() []string
- func (u UnimplementedClaims) GetExpiration() time.Time
- func (u UnimplementedClaims) GetExtra() map[string]string
- func (u UnimplementedClaims) GetIssuedAt() time.Time
- func (u UnimplementedClaims) GetIssuer() string
- func (u UnimplementedClaims) GetJwtID() string
- func (u UnimplementedClaims) GetNotBefore() time.Time
- func (u UnimplementedClaims) GetScopes() map[string]bool
- func (u UnimplementedClaims) GetSubject() string
Constants ¶
const (
HeaderAuthorize = "Authorization"
)
const ( // SchemeNTLM represents an NTLM authorization. SchemeNTLM = SchemeNegotiate )
const (
TokenNamespace = "security:token"
)
Variables ¶
This section is empty.
Functions ¶
func NewSecurityCache ¶ added in v0.0.92
Types ¶
type Authenticator ¶
type Authenticator interface {
// AuthenticateToken returns a nil error and the AuthClaims info (if available).
AuthenticateToken(string) (Claims, error)
// AuthenticateTokenContext returns a nil error and the AuthClaims info (if available).
// if the subject is authenticated or a non-nil error with an appropriate error cause otherwise.
AuthenticateTokenContext(context.Context, TokenType) (Claims, error)
// Authenticate validates if a token is valid.
Authenticate(context.Context, string) (bool, error)
// AuthenticateContext validates if a token is valid.
AuthenticateContext(context.Context, TokenType, string) (bool, error)
// CreateToken inject user claims into token string.
CreateToken(Claims) (string, error)
// CreateTokenContext inject user claims into context.
CreateTokenContext(context.Context, TokenType, Claims) (context.Context, error)
// DestroyToken invalidate a token by removing it from the token store.
DestroyToken(context.Context, string) error
// DestroyTokenContext invalidate a token by removing it from the token store.
DestroyTokenContext(context.Context, TokenType, string) error
// Close Cleans up the authenticator.
Close()
}
Authenticator interface
type Claims ¶
type Claims interface {
// GetSubject returns the subject of the security
GetSubject() string
// GetIssuer returns the issuer of the security
GetIssuer() string
// GetAudience returns the audience of the security
GetAudience() []string
// GetExpiration returns the expiration time of the security
GetExpiration() time.Time
// GetNotBefore returns the time before which the security cannot be accepted
GetNotBefore() time.Time
// GetIssuedAt returns the time at which the security was issued
GetIssuedAt() time.Time
// GetJWTID returns the unique identifier for the security
GetJWTID() string
// GetScopes returns the scopes associated with the security
GetScopes() map[string]bool
// GetExtra returns any additional data associated with the security
GetExtra() map[string]string
}
Claims is an interface that defines the methods that a security claims object should have
type Policy ¶ added in v0.0.20
type Policy interface {
// GetSubject returns the subject of the policy
GetSubject() string
// GetObject returns the object of the policy
GetObject() string
// GetAction returns the action of the policy
GetAction() string
// GetDomain returns the domain of the policy
GetDomain() []string
// GetExtra returns the extra information of the policy
GetExtra() map[string]string
}
Policy is an interface that defines the methods for a policy
type PolicyChecker ¶ added in v0.1.7
type PolicyChecker interface {
// CheckPolicy checks if the policy for a given subject, object, action, domain and extra is allowed
CheckPolicy(Policy) bool
// CheckPolicyContext checks if the policy for a given subject, object, action
CheckPolicyContext(context.Context, TokenType, Policy) bool
}
PolicyChecker is an interface that defines the methods for a policy checker
type PolicyManager ¶
type PolicyManager interface {
// AddPolicy adds a policy for a given subject, object, action, domain and extra
AddPolicy(sec string, pt string, rule []string) error
// RemovePolicy removes a policy for a given subject, object, action, domain and extra
RemovePolicy(sec string, pt string, rule []string) error
// GetPolicy returns the policy for a given subject, object, action, domain and extra
GetPolicy(subject string, object string, action string, domain []string, extra map[string]string) Policy
// SetPolicy sets the policy for a given subject, object, action, domain and extra
SetPolicy(subject string, object string, action string, domain []string, extra map[string]string)
// SetPolicies sets the policies for a given context
SetPolicies(context.Context, map[string]Policy) error
}
PolicyManager is an interface that defines the methods for a policy manager
type Scheme ¶
type Scheme int
Scheme represents the type of authorization.
const ( // SchemeAnonymous represents an anonymous authorization. SchemeAnonymous Scheme = iota // SchemeBasic represents a basic authorization. SchemeBasic // SchemeBearer represents a bearer authorization. SchemeBearer // SchemeDigest represents a digest authorization. SchemeDigest // SchemeHOBA represents a HTTP Origin-Bound Authentication (HOBA) authorization. SchemeHOBA // SchemeMutual represents a mutual authentication. SchemeMutual // SchemeNegotiate represents a negotiate authorization. SchemeNegotiate // SchemeVapid represents a VAPID authorization. SchemeVapid // SchemeSCRAM represents a SCRAM authorization. SchemeSCRAM // SchemeAWS4HMAC256 represents an AWS4-HMAC-SHA256 authorization. SchemeAWS4HMAC256 // SchemeDPoP represents a DPoP authorization. SchemeDPoP // SchemeGNAP represents a GNAP authorization. SchemeGNAP // SchemePrivate represents a private authorization. SchemePrivate // SchemeOAuth represents an OAuth authorization. SchemeOAuth // SchemeUnknown represents an unknown authorization. SchemeUnknown SchemeMax )
type Serializer ¶
type Serializer interface {
// Serialize serializes the given data into a byte slice
Serialize(ctx context.Context, data Claims) ([]byte, error)
// Deserialize deserializes the given byte slice into the given data
Deserialize(ctx context.Context, data []byte) (Claims, error)
}
Serializer is an interface that defines the methods for a serializer
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 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
type UnimplementedClaims ¶
type UnimplementedClaims struct {
}
UnimplementedClaims is a struct that implements the Claims interface
func (UnimplementedClaims) GetAudience ¶
func (u UnimplementedClaims) GetAudience() []string
GetAudience returns an empty slice
func (UnimplementedClaims) GetExpiration ¶
func (u UnimplementedClaims) GetExpiration() time.Time
GetExpiration returns the current time
func (UnimplementedClaims) GetExtra ¶
func (u UnimplementedClaims) GetExtra() map[string]string
GetExtra returns an empty map
func (UnimplementedClaims) GetIssuedAt ¶
func (u UnimplementedClaims) GetIssuedAt() time.Time
GetIssuedAt returns the current time
func (UnimplementedClaims) GetIssuer ¶
func (u UnimplementedClaims) GetIssuer() string
GetIssuer returns an empty string
func (UnimplementedClaims) GetJwtID ¶
func (u UnimplementedClaims) GetJwtID() string
GetJwtID returns an empty string
func (UnimplementedClaims) GetNotBefore ¶
func (u UnimplementedClaims) GetNotBefore() time.Time
GetNotBefore returns the current time
func (UnimplementedClaims) GetScopes ¶
func (u UnimplementedClaims) GetScopes() map[string]bool
GetScopes returns an empty map
func (UnimplementedClaims) GetSubject ¶
func (u UnimplementedClaims) GetSubject() string
GetSubject returns an empty string