From 180ecc36cc92610711a666e4c9abf4c5a4ed184e Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 18 Sep 2020 21:12:59 +0300 Subject: [PATCH] Improve detecting login flows supported by homeserver --- matrix/matrix.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/matrix/matrix.go b/matrix/matrix.go index d54ad82..bac95b9 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -252,13 +252,14 @@ func (c *Container) Login(user, password string) error { if err != nil { return err } - if len(resp.Flows) == 1 && resp.Flows[0].Type == "m.login.password" { - return c.PasswordLogin(user, password) - } else if len(resp.Flows) == 2 && resp.Flows[0].Type == "m.login.sso" && resp.Flows[1].Type == "m.login.token" { - return c.SingleSignOn() - } else { - return fmt.Errorf("no supported login flows") + for _, flow := range resp.Flows { + if flow.Type == "m.login.password" { + return c.PasswordLogin(user, password) + } else if flow.Type == "m.login.sso" { + return c.SingleSignOn() + } } + return fmt.Errorf("no supported login flows") } // Logout revokes the access token, stops the syncer and calls the OnLogout() method of the UI.