mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-07-04 17:06:49 +00:00
Oauth2 support
This commit is contained in:
@ -2,19 +2,31 @@ package setting
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// 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
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(m.Value.String()), &l); err != nil {
|
||||
return l, err
|
||||
var r []string
|
||||
if err := json.Unmarshal([]byte(m.Value.String()), &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return l, nil
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// AuthMethodEnabled checks that the auth method given is
|
||||
// enabled in the db setting
|
||||
func AuthMethodEnabled(method string) bool {
|
||||
r, err := GetAuthMethods()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return slices.Contains(r, method)
|
||||
}
|
||||
|
42
backend/internal/entity/setting/oauth.go
Normal file
42
backend/internal/entity/setting/oauth.go
Normal file
@ -0,0 +1,42 @@
|
||||
package setting
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// OAuthSettings are the settings for OAuth that come from
|
||||
// the `oauth-auth` setting value
|
||||
type OAuthSettings struct {
|
||||
AutoCreateUser bool `json:"auto_create_user"`
|
||||
ClientID string `json:"client_id"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
AuthURL string `json:"authorization_url"`
|
||||
TokenURL string `json:"token_url"`
|
||||
Identifier string `json:"identifier"`
|
||||
LogoutURL string `json:"logout_url"`
|
||||
Scopes []string `json:"scopes"`
|
||||
ResourceURL string `json:"resource_url"`
|
||||
}
|
||||
|
||||
// GetOAuthSettings will return the OAuth settings
|
||||
func GetOAuthSettings() (OAuthSettings, error) {
|
||||
var o OAuthSettings
|
||||
var m Model
|
||||
if err := m.LoadByName("oauth-auth"); err != nil {
|
||||
return o, err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(m.Value.String()), &o); err != nil {
|
||||
return o, err
|
||||
}
|
||||
|
||||
o.ApplyDefaults()
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// ApplyDefaults will ensure there are defaults set
|
||||
func (m *OAuthSettings) ApplyDefaults() {
|
||||
if m.Identifier == "" {
|
||||
m.Identifier = "email"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user