auth

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SigningKey []byte

SigningKey is the HMAC-SHA256 key for JWTs. Initialized by InitSigningKey from the database.

Functions

func GenerateJWT

func GenerateJWT(userID int64, expiresIn time.Duration) (string, error)

GenerateJWT creates an HS256 JWT with the given user ID and expiry.

func GenerateURLToken added in v0.2.2

func GenerateURLToken(expiresIn time.Duration) (string, error)

GenerateURLToken creates a short-lived JWT for use as a URL query parameter.

func InitSigningKey added in v0.2.2

func InitSigningKey(ctx context.Context, database interface {
	GetConfig(context.Context, string) (string, error)
	SetConfig(context.Context, string, string) error
}) error

InitSigningKey loads or generates the JWT signing key, persisted in the DB.

func ParseJWT

func ParseJWT(tokenString string) (int64, error)

ParseJWT validates and parses an HS256 JWT, returning the user ID.

func UserIDFromRequest

func UserIDFromRequest(r *http.Request, authEnabled bool) int64

UserIDFromRequest extracts the user ID from the Authorization Bearer token. Returns 1 (default user) if auth is disabled. Returns 0 if auth is enabled and token is missing/invalid.

func ValidateURLToken added in v0.2.2

func ValidateURLToken(token string) bool

ValidateURLToken checks a token from a URL query parameter.

Types

type DeviceStore

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

DeviceStore manages pending device authorization requests.

func NewDeviceStore

func NewDeviceStore() *DeviceStore

NewDeviceStore creates a new device authorization store.

func (*DeviceStore) Approve

func (s *DeviceStore) Approve(userCode string, userID int64) bool

Approve marks a pending auth as approved with the given user ID.

func (*DeviceStore) Check

func (s *DeviceStore) Check(deviceCode string) (*PendingAuth, bool)

Check returns the pending auth status for a device code.

func (*DeviceStore) NewPending

func (s *DeviceStore) NewPending(expiresIn time.Duration) (deviceCode, userCode string)

NewPending creates a new pending device auth and returns device code + user code.

func (*DeviceStore) Remove

func (s *DeviceStore) Remove(deviceCode string)

Remove deletes a pending auth entry.

type PendingAuth

type PendingAuth struct {
	UserCode  string
	ExpiresAt time.Time
	Approved  bool
	UserID    int64
}

PendingAuth represents a pending device authorization request.

Jump to

Keyboard shortcuts

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