feat: 绑定 oauth2

This commit is contained in:
naiba
2024-12-28 23:50:59 +08:00
parent 8554f3eba7
commit 18020939da
15 changed files with 360 additions and 24 deletions

View File

@@ -1,8 +1,10 @@
package model
import (
"maps"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
@@ -21,6 +23,17 @@ const (
ConfigCoverIgnoreAll
)
type ConfigForGuests struct {
Language string `json:"language"`
SiteName string `json:"site_name"`
CustomCode string `json:"custom_code,omitempty"`
CustomCodeDashboard string `json:"custom_code_dashboard,omitempty"`
Oauth2Providers []string `json:"oauth2_providers,omitempty"`
InstallHost string `json:"install_host,omitempty"`
TLS bool `json:"tls,omitempty"`
}
type Config struct {
Debug bool `mapstructure:"debug" json:"debug,omitempty"` // debug模式开关
RealIPHeader string `mapstructure:"real_ip_header" json:"real_ip_header,omitempty"` // 真实IP
@@ -52,6 +65,11 @@ type Config struct {
CustomCode string `mapstructure:"custom_code" json:"custom_code,omitempty"`
CustomCodeDashboard string `mapstructure:"custom_code_dashboard" json:"custom_code_dashboard,omitempty"`
// oauth2 配置
Oauth2 map[string]*Oauth2Config `mapstructure:"oauth2" json:"oauth2,omitempty"`
// oauth2 供应商列表,无需配置,自动生成
Oauth2Providers []string `yaml:"-" json:"oauth2_providers,omitempty"`
k *koanf.Koanf `json:"-"`
filePath string `json:"-"`
}
@@ -132,6 +150,8 @@ func (c *Config) Read(path string, frontendTemplates []FrontendTemplate) error {
}
}
c.Oauth2Providers = slices.Collect(maps.Keys(c.Oauth2))
c.updateIgnoredIPNotificationID()
return nil
}