auth: Registrierung, Login, Logout, per-user Sessions (Backend)
This commit is contained in:
parent
c7b4acea02
commit
0ef39cffd6
12 changed files with 703 additions and 40 deletions
|
|
@ -76,7 +76,12 @@ type Tools struct {
|
|||
|
||||
type Config struct {
|
||||
Listen string `yaml:"listen" json:"listen"`
|
||||
// AuthToken is an optional static admin token (sees all sessions). Users log in via /api/auth.
|
||||
AuthToken string `yaml:"auth_token" json:"auth_token"`
|
||||
// AllowRegistration enables self-service sign-up (default true).
|
||||
AllowRegistration *bool `yaml:"allow_registration" json:"allow_registration"`
|
||||
// TokenTTLHours is the lifetime of login tokens (default 720 = 30 days).
|
||||
TokenTTLHours int `yaml:"token_ttl_hours" json:"token_ttl_hours"`
|
||||
// AllowedOrigins for browser WebSocket/CORS. Empty = same host only. "*" must be set explicitly.
|
||||
AllowedOrigins []string `yaml:"allowed_origins" json:"allowed_origins"`
|
||||
DataDir string `yaml:"data_dir" json:"data_dir"`
|
||||
|
|
@ -153,6 +158,10 @@ func applyEnv(c *Config, get func(string) string) {
|
|||
set("BYTECLAW_LLM_BASE_URL", &c.LLM.BaseURL)
|
||||
set("BYTECLAW_LLM_API_KEY", &c.LLM.APIKey)
|
||||
set("BYTECLAW_LLM_MODEL", &c.LLM.Model)
|
||||
if v := get("BYTECLAW_ALLOW_REGISTRATION"); v != "" {
|
||||
b := v == "1" || strings.EqualFold(v, "true") || strings.EqualFold(v, "yes")
|
||||
c.AllowRegistration = &b
|
||||
}
|
||||
if v := get("BYTECLAW_ALLOWED_ORIGINS"); v != "" {
|
||||
c.AllowedOrigins = nil
|
||||
for _, o := range strings.Split(v, ",") {
|
||||
|
|
@ -163,11 +172,14 @@ func applyEnv(c *Config, get func(string) string) {
|
|||
}
|
||||
}
|
||||
|
||||
// RegistrationAllowed reports allow_registration (default true).
|
||||
func (c Config) RegistrationAllowed() bool { return c.AllowRegistration == nil || *c.AllowRegistration }
|
||||
|
||||
// Validate enforces required fields and secure settings.
|
||||
func (c Config) Validate() error {
|
||||
var errs []error
|
||||
if len(c.AuthToken) < 16 {
|
||||
errs = append(errs, errors.New("auth_token must be set and at least 16 characters (BYTECLAW_AUTH_TOKEN)"))
|
||||
if c.AuthToken != "" && len(c.AuthToken) < 16 {
|
||||
errs = append(errs, errors.New("auth_token must be at least 16 characters when set (BYTECLAW_AUTH_TOKEN)"))
|
||||
}
|
||||
if c.LLM.BaseURL == "" || c.LLM.Model == "" {
|
||||
errs = append(errs, errors.New("llm.base_url and llm.model are required"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue