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 { type ServerConfig struct {
ID uuid.UUID ID uuid.UUID
Nickname string Nickname string
Hostname string Hostname string
Username string Username string
Default bool LegacyAuth bool
Default bool
} }
type AppConfig struct { 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{ s := &ServerConfig{
ID: uuid.New(), ID: uuid.New(),
Nickname: nickname, Nickname: nickname,
Hostname: hostname, Hostname: hostname,
Username: username, Username: username,
LegacyAuth: legacyAuth,
} }
c.Servers = append(c.Servers, s) c.Servers = append(c.Servers, s)
return s return s
+11 -8
View File
@@ -25,7 +25,7 @@ func NewServerManager() *ServerManager {
} }
func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) error { 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 { if err != nil {
return err return err
} }
@@ -37,11 +37,13 @@ func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) err
return nil 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 err := ErrUnreachable
done := make(chan bool) done := make(chan bool)
go func() { go func() {
_, err = s.testConnectionAndCreateClient(hostname, username, password) _, err = s.testConnectionAndCreateClient(hostname, username, password, legacyAuth)
close(done) close(done)
}() }()
t := time.NewTimer(timeout) 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{ cli := &subsonic.Client{
Client: &http.Client{}, Client: &http.Client{},
BaseUrl: hostname, BaseUrl: hostname,
User: username, User: username,
ClientName: "supersonic", PasswordAuth: legacyAuth,
ClientName: "supersonic",
} }
if !cli.Ping() { if !cli.Ping() {
return nil, ErrUnreachable return nil, ErrUnreachable
+5 -4
View File
@@ -102,7 +102,7 @@ func (m *Controller) PromptForFirstServer() {
if m.testConnectionAndUpdateDialogText(d) { if m.testConnectionAndUpdateDialogText(d) {
// connection is good // connection is good
pop.Hide() pop.Hide()
server := m.App.Config.AddServer(d.Nickname, d.Host, d.Username) server := m.App.Config.AddServer(d.Nickname, d.Host, d.Username, d.LegacyAuth)
if err := m.App.ServerManager.SetServerPassword(server, d.Password); err != nil { if err := m.App.ServerManager.SetServerPassword(server, d.Password); err != nil {
log.Printf("error setting keyring credentials: %v", err) log.Printf("error setting keyring credentials: %v", err)
// TODO: handle? // TODO: handle?
@@ -172,7 +172,7 @@ func (m *Controller) PromptForLoginAndConnect() {
d.DisableSubmit() d.DisableSubmit()
d.SetInfoText("Testing connection...") d.SetInfoText("Testing connection...")
go func() { go func() {
err := m.App.ServerManager.TestConnectionAndAuth(server.Hostname, server.Username, password, 5*time.Second) err := m.App.ServerManager.TestConnectionAndAuth(server.Hostname, server.Username, password, server.LegacyAuth, 5*time.Second)
if err == backend.ErrUnreachable { if err == backend.ErrUnreachable {
d.SetErrorText("Server unreachable") d.SetErrorText("Server unreachable")
} else if err != nil { } else if err != nil {
@@ -197,6 +197,7 @@ func (m *Controller) PromptForLoginAndConnect() {
server.Hostname = editD.Host server.Hostname = editD.Host
server.Nickname = editD.Nickname server.Nickname = editD.Nickname
server.Username = editD.Username server.Username = editD.Username
server.LegacyAuth = editD.LegacyAuth
m.trySetPasswordAndConnectToServer(server, editD.Password) m.trySetPasswordAndConnectToServer(server, editD.Password)
} }
d.EnableSubmit() d.EnableSubmit()
@@ -226,7 +227,7 @@ func (c *Controller) trySetPasswordAndConnectToServer(server *backend.ServerConf
} }
func (c *Controller) tryConnectToServer(server *backend.ServerConfig, password string) error { func (c *Controller) tryConnectToServer(server *backend.ServerConfig, password string) error {
if err := c.App.ServerManager.TestConnectionAndAuth(server.Hostname, server.Username, password, 10*time.Second); err != nil { if err := c.App.ServerManager.TestConnectionAndAuth(server.Hostname, server.Username, password, server.LegacyAuth, 10*time.Second); err != nil {
return err return err
} }
if err := c.App.ServerManager.ConnectToServer(server, password); err != nil { if err := c.App.ServerManager.ConnectToServer(server, password); err != nil {
@@ -238,7 +239,7 @@ func (c *Controller) tryConnectToServer(server *backend.ServerConfig, password s
func (c *Controller) testConnectionAndUpdateDialogText(dlg *dialogs.AddEditServerDialog) bool { func (c *Controller) testConnectionAndUpdateDialogText(dlg *dialogs.AddEditServerDialog) bool {
dlg.SetInfoText("Testing connection...") dlg.SetInfoText("Testing connection...")
err := c.App.ServerManager.TestConnectionAndAuth(dlg.Host, dlg.Username, dlg.Password, 5*time.Second) err := c.App.ServerManager.TestConnectionAndAuth(dlg.Host, dlg.Username, dlg.Password, dlg.LegacyAuth, 5*time.Second)
if err == backend.ErrUnreachable { if err == backend.ErrUnreachable {
dlg.SetErrorText("Could not reach server (wrong hostname?)") dlg.SetErrorText("Could not reach server (wrong hostname?)")
return false return false
+10 -5
View File
@@ -14,11 +14,12 @@ import (
type AddEditServerDialog struct { type AddEditServerDialog struct {
widget.BaseWidget widget.BaseWidget
Nickname string Nickname string
Host string Host string
Username string Username string
Password string Password string
OnSubmit func() LegacyAuth bool
OnSubmit func()
submitBtn *widget.Button submitBtn *widget.Button
promptText *widget.RichText promptText *widget.RichText
@@ -34,6 +35,7 @@ func NewAddEditServerDialog(title string, prefillServer *backend.ServerConfig) *
a.Nickname = prefillServer.Nickname a.Nickname = prefillServer.Nickname
a.Host = prefillServer.Hostname a.Host = prefillServer.Hostname
a.Username = prefillServer.Username a.Username = prefillServer.Username
a.LegacyAuth = prefillServer.LegacyAuth
} }
titleLabel := widget.NewLabel(title) titleLabel := widget.NewLabel(title)
@@ -53,6 +55,8 @@ func NewAddEditServerDialog(title string, prefillServer *backend.ServerConfig) *
a.promptText = widget.NewRichTextWithText("") a.promptText = widget.NewRichTextWithText("")
a.promptText.Hidden = true a.promptText.Hidden = true
legacyAuthCheck := widget.NewCheckWithData("Use legacy authentication", binding.BindBool(&a.LegacyAuth))
a.container = container.NewVBox( a.container = container.NewVBox(
container.NewHBox(layout.NewSpacer(), titleLabel, layout.NewSpacer()), container.NewHBox(layout.NewSpacer(), titleLabel, layout.NewSpacer()),
container.New(layout.NewFormLayout(), container.New(layout.NewFormLayout(),
@@ -65,6 +69,7 @@ func NewAddEditServerDialog(title string, prefillServer *backend.ServerConfig) *
widget.NewLabel("Password"), widget.NewLabel("Password"),
passField, passField,
), ),
container.NewHBox(layout.NewSpacer(), legacyAuthCheck),
widget.NewSeparator(), widget.NewSeparator(),
container.NewHBox( container.NewHBox(
a.promptText, a.promptText,