Add wrapper for account changing password

change-password
Tulir Asokan 2023-07-24 14:16:03 +03:00
parent ab9d6e5eb5
commit 682f4670da
3 changed files with 29 additions and 0 deletions

View File

@ -789,6 +789,27 @@ func (cli *Client) RegisterDummy(req *ReqRegister) (*RespRegister, error) {
return res, nil
}
func (cli *Client) ChangePassword(req *ReqChangePassword) (resp *RespChangePassword, uiaResp *RespUserInteractive, err error) {
var bodyBytes []byte
bodyBytes, err = cli.MakeFullRequest(FullRequest{
Method: http.MethodPost,
URL: cli.BuildClientURL("v3", "account", "password"),
RequestJSON: req,
SensitiveContent: len(req.NewPassword) > 0,
})
if err != nil {
httpErr, ok := err.(HTTPError)
// if response has a 401 status, but doesn't have the errcode field, it's probably a UIA response.
if ok && httpErr.IsStatus(http.StatusUnauthorized) && httpErr.RespError == nil {
err = json.Unmarshal(bodyBytes, &uiaResp)
}
} else {
// body should be RespRegister
err = json.Unmarshal(bodyBytes, &resp)
}
return
}
// GetLoginFlows fetches the login flows that the homeserver supports using https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3login
func (cli *Client) GetLoginFlows() (resp *RespLoginFlows, err error) {
urlPath := cli.BuildClientURL("v3", "login")

View File

@ -55,6 +55,12 @@ type ReqRegister struct {
Type AuthType `json:"type,omitempty"`
}
type ReqChangePassword struct {
Auth any `json:"auth"`
LogoutDevices bool `json:"logout_devices"`
NewPassword string `json:"new_password"`
}
type BaseAuthData struct {
Type AuthType `json:"type"`
Session string `json:"session,omitempty"`

View File

@ -184,6 +184,8 @@ type RespRegister struct {
HomeServer string `json:"home_server,omitempty"`
}
type RespChangePassword struct{}
type LoginFlow struct {
Type AuthType `json:"type"`
}