auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey() (string, error)

GenerateKey creates a new API key with the mtk_ prefix

func GetOrgID

func GetOrgID(c *fiber.Ctx) string

GetOrgID extracts the org_id from the Fiber context

func HasPermission

func HasPermission(info *KeyInfo, permission string) bool

HasPermission checks if a key has a specific permission

func RequireAuth

func RequireAuth(m *Manager) fiber.Handler

RequireAuth returns Fiber middleware that validates API keys

Types

type KeyInfo

type KeyInfo struct {
	ID          int64     `json:"id"`
	Name        string    `json:"name"`
	OrgID       string    `json:"org_id"`
	Permissions []string  `json:"permissions"`
	CreatedAt   time.Time `json:"created_at"`
	ExpiresAt   time.Time `json:"expires_at,omitempty"`
	Enabled     bool      `json:"enabled"`
}

KeyInfo represents API key metadata

func GetKeyInfo

func GetKeyInfo(c *fiber.Ctx) *KeyInfo

GetKeyInfo extracts the key info from the Fiber context

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles API key authentication

func NewManager

func NewManager(db *sql.DB, logger zerolog.Logger) *Manager

NewManager creates a new auth manager using the metadata DB

func (*Manager) Close

func (m *Manager) Close()

Close stops the auth manager

func (*Manager) CreateKey

func (m *Manager) CreateKey(name, orgID, permissions string) (string, error)

CreateKey creates a new API key for an organization

func (*Manager) DeleteKey

func (m *Manager) DeleteKey(id int64) error

DeleteKey deletes an API key

func (*Manager) EnsureBootstrap

func (m *Manager) EnsureBootstrap() (string, error)

EnsureBootstrap creates the default org and admin key if none exist

func (*Manager) ListKeys

func (m *Manager) ListKeys(orgID string) ([]KeyInfo, error)

ListKeys returns all keys for an org (without hashes)

func (*Manager) VerifyKey

func (m *Manager) VerifyKey(key string) *KeyInfo

VerifyKey verifies an API key and returns key info if valid

Jump to

Keyboard shortcuts

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