add legacy auth support

This commit is contained in:
Drew Weymouth
2023-03-09 17:22:41 -08:00
committed by Drew Weymouth
parent c8fd7038fb
commit f14dda8f45
4 changed files with 38 additions and 27 deletions
+12 -10
View File
@@ -8,11 +8,12 @@ import (
)
type ServerConfig struct {
ID uuid.UUID
Nickname string
Hostname string
Username string
Default bool
ID uuid.UUID
Nickname string
Hostname string
Username string
LegacyAuth bool
Default bool
}
type AppConfig struct {
@@ -124,12 +125,13 @@ func (c *Config) SetDefaultServer(serverID uuid.UUID) {
}
}
func (c *Config) AddServer(nickname, hostname, username string) *ServerConfig {
func (c *Config) AddServer(nickname, hostname, username string, legacyAuth bool) *ServerConfig {
s := &ServerConfig{
ID: uuid.New(),
Nickname: nickname,
Hostname: hostname,
Username: username,
ID: uuid.New(),
Nickname: nickname,
Hostname: hostname,
Username: username,
LegacyAuth: legacyAuth,
}
c.Servers = append(c.Servers, s)
return s
+11 -8
View File
@@ -25,7 +25,7 @@ func NewServerManager() *ServerManager {
}
func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) error {
cli, err := s.testConnectionAndCreateClient(conf.Hostname, conf.Username, password)
cli, err := s.testConnectionAndCreateClient(conf.Hostname, conf.Username, password, conf.LegacyAuth)
if err != nil {
return err
}
@@ -37,11 +37,13 @@ func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) err
return nil
}
func (s *ServerManager) TestConnectionAndAuth(hostname, username, password string, timeout time.Duration) error {
func (s *ServerManager) TestConnectionAndAuth(
hostname, username, password string, legacyAuth bool, timeout time.Duration,
) error {
err := ErrUnreachable
done := make(chan bool)
go func() {
_, err = s.testConnectionAndCreateClient(hostname, username, password)
_, err = s.testConnectionAndCreateClient(hostname, username, password, legacyAuth)
close(done)
}()
t := time.NewTimer(timeout)
@@ -54,12 +56,13 @@ func (s *ServerManager) TestConnectionAndAuth(hostname, username, password strin
}
}
func (s *ServerManager) testConnectionAndCreateClient(hostname, username, password string) (*subsonic.Client, error) {
func (s *ServerManager) testConnectionAndCreateClient(hostname, username, password string, legacyAuth bool) (*subsonic.Client, error) {
cli := &subsonic.Client{
Client: &http.Client{},
BaseUrl: hostname,
User: username,
ClientName: "supersonic",
Client: &http.Client{},
BaseUrl: hostname,
User: username,
PasswordAuth: legacyAuth,
ClientName: "supersonic",
}
if !cli.Ping() {
return nil, ErrUnreachable