mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Add option to store credentials directly in Login()
This commit is contained in:
parent
ea59176c9e
commit
1ee81815fd
3 changed files with 12 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue