Add tool to get Matrix access token.

change-name
Robert Jacob 5 years ago
parent 4fcfbd3cfc
commit 913ae8e10b
  1. 61
      cmd/matrix-token/main.go

@ -0,0 +1,61 @@
package main
import (
"fmt"
"log"
"github.com/matrix-org/gomatrix"
"github.com/spf13/pflag"
)
var (
homeServer string
userID string
password string
)
func main() {
log.SetFlags(0)
pflag.StringVarP(&homeServer, "home-server", "s", "", "Matrix homeserver to login to.")
pflag.StringVarP(&userID, "user", "u", "", "UserID of user to login with.")
pflag.StringVarP(&password, "password", "p", "", "Password of user.")
pflag.Parse()
if homeServer == "" {
log.Println("Need server!")
pflag.Usage()
return
}
if userID == "" {
log.Println("Need user-ID!")
pflag.Usage()
return
}
if password == "" {
log.Println("Need password!")
pflag.Usage()
return
}
log.Printf("Getting a token for user %q on %q...", userID, homeServer)
cli, err := gomatrix.NewClient(homeServer, "", "")
if err != nil {
log.Fatalf("Error creating client: %s", err)
}
res, err := cli.Login(&gomatrix.ReqLogin{
Type: "m.login.password",
User: userID,
Password: password,
})
if err != nil {
log.Fatalf("Error during login: %s", err)
}
log.Println("Login successful.")
fmt.Println(res.AccessToken)
}
Loading…
Cancel
Save