a simple matrix package for basic actions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
966 B

package matrix
import (
// Login logs in to the homeserver and returns an Authinfo struct containing
// information such as the UserID, the HomeServer of the entity that was logged
// and most important: the AccessToken for further verification
func Login(username, password, homeserver string) (Authinfo, error) {
cli := gentleman.New()
req := cli.Request()
data := map[string]string{
"type": "m.login.password",
"user": username,
"password": password,
res, err := req.Send()
if err != nil {
return Authinfo{}, err
if !res.Ok {
return Authinfo{}, err
var authinfo Authinfo
if err := json.Unmarshal(res.Bytes(), &authinfo); err != nil {
return Authinfo{}, err
authinfo.HomeServer = homeserver
return authinfo, nil