Documentation
¶
Overview ¶
Package plugin defines the foundational contracts and shared execution context for authentication plugins.
Index ¶
Constants ¶
const ( // ContextKeyUser stores the current authenticated user domain entity. ContextKeyUser = "auth:user" // ContextKeySession stores the active session domain entity. ContextKeySession = "auth:session" // ContextKeyAccount stores the active account entity. ContextKeyAccount = "auth:account" // ContextKeyBearerToken stores the bearer or access token string. ContextKeyBearerToken = "auth:bearer_token" )
Standard context key constants stored in the shared thread-safe plugin.Context store.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the shared environment provided to plugins upon initialization, containing cryptographic tools, event buses, and a key-value store.
func NewContext ¶
func NewContext(crypto CryptoUtils, bus EventBus.Bus) *Context
NewContext creates a new Context with the specified cryptographic utilities and event bus.
func (*Context) Crypto ¶
func (c *Context) Crypto() CryptoUtils
Crypto returns the cryptographic utilities instance.
func (*Context) Events ¶
Events returns the shared EventBus instance for subscribing or publishing plugin lifecycle events.
type CryptoUtils ¶
type CryptoUtils interface {
HashPassword(password string) (string, error)
ComparePassword(hash, password string) bool
GenerateRandomToken(length int) (string, error)
}
CryptoUtils defines cryptographic utility operations provided to plugins (hashing, comparison, random tokens).
type ExtraContainer ¶ added in v0.14.0
type ExtraContainer struct {
// Extra holds dynamic metadata passed through event interceptors or custom extensions.
Extra map[string]any `json:"extra,omitempty"`
}
ExtraContainer provides a reusable map for dynamic metadata with Set and Get methods. Embed plugin.ExtraContainer in DTO parameter structs to eliminate repetitive metadata handling code.
func (*ExtraContainer) Get ¶ added in v0.14.0
func (e *ExtraContainer) Get(key string) (any, bool)
Get retrieves a value from the Extra metadata map by key.
func (*ExtraContainer) Set ¶ added in v0.14.0
func (e *ExtraContainer) Set(key string, val any)
Set stores a key-value pair in the Extra metadata map.
type Plugin ¶
type Plugin interface {
// ID returns a unique identifier for the plugin (e.g., "email-password", "two-factor").
ID() string
// Init initializes the plugin with the shared execution context.
Init(ctx *Context) error
}
Plugin defines the interface that all modular authentication plugins must implement.