plugin

package
v0.27.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package plugin defines the foundational contracts and shared execution context for authentication plugins.

Index

Constants

View Source
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

func (c *Context) Events() EventBus.Bus

Events returns the shared EventBus instance for subscribing or publishing plugin lifecycle events.

func (*Context) Get

func (c *Context) Get(key string) (any, bool)

Get retrieves a value from the shared thread-safe context store by key.

func (*Context) Set

func (c *Context) Set(key string, value any)

Set stores a key-value pair in the shared thread-safe context store.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL