auth

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT-0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasPermission

func HasPermission(permissions []string, required string) bool

HasPermission checks if a user has a specific permission

Types

type Challenge added in v0.4.2

type Challenge struct {
	Nonce     string    `json:"nonce"`
	ExpiresAt time.Time `json:"expires_at"`
}

Challenge represents an authentication challenge

type ChallengeStore added in v0.4.2

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

ChallengeStore manages active authentication challenges

func NewChallengeStore added in v0.4.2

func NewChallengeStore() *ChallengeStore

NewChallengeStore creates a new challenge store

func (*ChallengeStore) GenerateChallenge added in v0.4.2

func (cs *ChallengeStore) GenerateChallenge() (*Challenge, error)

GenerateChallenge creates a new random challenge

func (*ChallengeStore) ValidateResponse added in v0.4.2

func (cs *ChallengeStore) ValidateResponse(nonce, response, token string) (bool, error)

ValidateResponse validates an HMAC response against a challenge

type Credential

type Credential struct {
	Type  string // e.g. "ssh", "token", "jwt"
	Value string
}

Credential represents an authentication credential (placeholder).

func (*Credential) Validate

func (c *Credential) Validate() bool

Validate checks the credential (placeholder).

type Middleware

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

Middleware provides authentication middleware for HTTP handlers

func NewMiddleware

func NewMiddleware(store *TokenStore) *Middleware

NewMiddleware creates a new auth middleware

func (*Middleware) HandleChallenge added in v0.4.2

func (m *Middleware) HandleChallenge(w http.ResponseWriter, r *http.Request)

HandleChallenge returns a new authentication challenge

func (*Middleware) OptionalAuth

func (m *Middleware) OptionalAuth(next http.HandlerFunc) http.HandlerFunc

OptionalAuth wraps a handler to optionally accept authentication

func (*Middleware) RequireAuth

func (m *Middleware) RequireAuth(requiredPermission string, next http.HandlerFunc) http.HandlerFunc

RequireAuth wraps a handler to require authentication Supports both Bearer token and Challenge-Response authentication

type Token

type Token struct {
	ID          string    `json:"id"`
	TokenHash   string    `json:"token_hash"`
	User        string    `json:"user"`
	Permissions []string  `json:"permissions"`
	CreatedAt   time.Time `json:"created_at"`
	ExpiresAt   time.Time `json:"expires_at"`
	Revoked     bool      `json:"revoked"`
}

Token represents an authentication token

type TokenStore

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

TokenStore holds all tokens with thread-safe access

func NewTokenStore

func NewTokenStore(filename string) (*TokenStore, error)

NewTokenStore creates a new token store

func (*TokenStore) GetTokenByID added in v0.4.2

func (ts *TokenStore) GetTokenByID(tokenID string) *Token

GetTokenByID retrieves a token by its ID (for challenge-response auth)

func (*TokenStore) Load

func (ts *TokenStore) Load() error

Load reads tokens from file

func (*TokenStore) Reload

func (ts *TokenStore) Reload() error

Reload reloads tokens from file

func (*TokenStore) Validate

func (ts *TokenStore) Validate(tokenStr string) (string, []string, error)

Validate checks if a token is valid and returns the associated user and permissions

type TokenStoreFile

type TokenStoreFile struct {
	Tokens []Token `json:"tokens"`
}

TokenStoreFile represents the JSON file format

Jump to

Keyboard shortcuts

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