auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey(name string, expiresAt *time.Time) (plaintext string, key *models.APIKey, err error)

GenerateKey creates a cryptographically random API key with a readable prefix. Returns the plaintext key (shown once) and a models.APIKey ready to persist. expiresAt is optional; pass nil for a non-expiring key.

func HashKey

func HashKey(plaintext string) string

HashKey returns the SHA-256 hex digest of a plaintext key.

func Validate

func Validate(ctx context.Context, db *sqlx.DB, plaintext string) (*models.APIKey, error)

Validate looks up and validates the key, returning the matching APIKey record. It updates last_used_at as a side effect, throttled to at most once per lastUsedWriteInterval per key to reduce write pressure on the database.

Types

This section is empty.

Jump to

Keyboard shortcuts

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