Adds LDAP auth support

This commit is contained in:
Jamie Curnow
2024-11-02 21:36:07 +10:00
parent 8434a2d1fa
commit a277a5d167
54 changed files with 765 additions and 306 deletions

View File

@ -0,0 +1,20 @@
package setting
import (
"encoding/json"
)
// GetAuthMethods returns the authentication methods enabled for this site
func GetAuthMethods() ([]string, error) {
var l []string
var m Model
if err := m.LoadByName("auth-methods"); err != nil {
return l, err
}
if err := json.Unmarshal([]byte(m.Value.String()), &l); err != nil {
return l, err
}
return l, nil
}

View File

@ -0,0 +1,32 @@
package setting
import (
"encoding/json"
)
// LDAPSettings are the settings for LDAP that come from
// the `ldap-auth` setting value
type LDAPSettings struct {
Host string `json:"host"`
BaseDN string `json:"base_dn"`
UserDN string `json:"user_dn"`
EmailProperty string `json:"email_property"`
NameProperty string `json:"name_property"`
SelfFilter string `json:"self_filter"`
AutoCreateUser bool `json:"auto_create_user"`
}
// GetLDAPSettings will return the LDAP settings
func GetLDAPSettings() (LDAPSettings, error) {
var l LDAPSettings
var m Model
if err := m.LoadByName("ldap-auth"); err != nil {
return l, err
}
if err := json.Unmarshal([]byte(m.Value.String()), &l); err != nil {
return l, err
}
return l, nil
}