diff --git a/client.go b/client.go index 01ca1069..a5ff54e3 100644 --- a/client.go +++ b/client.go @@ -178,6 +178,8 @@ func (cli *Client) BuildURLWithQuery(urlPath URLPath, urlQuery map[string]string } // SetCredentials sets the user ID and access token on this client instance. +// +// Deprecated: use the StoreCredentials field in ReqLogin instead. func (cli *Client) SetCredentials(userID id.UserID, accessToken string) { cli.AccessToken = accessToken cli.UserID = userID @@ -470,10 +472,15 @@ func (cli *Client) GetLoginFlows() (resp *RespLoginFlows, err error) { } // Login a user to the homeserver according to http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login -// This does not set credentials on this client instance. See SetCredentials() instead. func (cli *Client) Login(req *ReqLogin) (resp *RespLogin, err error) { urlPath := cli.BuildURL("login") _, err = cli.MakeRequest("POST", urlPath, req, &resp) + if req.StoreCredentials && err == nil { + cli.DeviceID = resp.DeviceID + cli.AccessToken = resp.AccessToken + cli.UserID = resp.UserID + // TODO update cli.HomeserverURL based on the .well-known data in the login response + } return } diff --git a/requests.go b/requests.go index f15a2f31..74d474d8 100644 --- a/requests.go +++ b/requests.go @@ -38,6 +38,9 @@ type ReqLogin struct { Token string `json:"token,omitempty"` DeviceID id.DeviceID `json:"device_id,omitempty"` InitialDeviceDisplayName string `json:"initial_device_display_name,omitempty"` + + // Whether or not the returned credentials should be stored in the Client + StoreCredentials bool `json:"-"` } // ReqCreateRoom is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom diff --git a/responses.go b/responses.go index 1d7dc271..6a4d18fc 100644 --- a/responses.go +++ b/responses.go @@ -134,8 +134,8 @@ type RespLoginFlows struct { type RespLogin struct { AccessToken string `json:"access_token"` DeviceID id.DeviceID `json:"device_id"` - HomeServer string `json:"home_server"` UserID id.UserID `json:"user_id"` + // TODO add .well-known field here } // RespLogout is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout