Browse Source

Allow login using basic single device mfaCode

master
Gregory Rudolph 3 years ago
parent
commit
d6080be9d9
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 2
      botCommands.go
  2. 7
      commands.go
  3. 7
      login.go

2
botCommands.go

@ -9,7 +9,7 @@ func setupCommands() { @@ -9,7 +9,7 @@ func setupCommands() {
Commands: []chat1.UserBotCommandInput{
{
Name: "authenticate",
Description: "Authenticate with Tesla, please use exploding message for username/password OR a token.",
Description: "Authenticate with Tesla, please use exploding message for username/password (with optional mfa code) OR a token.",
Usage: "email@example.com Pa$$w0rd",
},
},

7
commands.go

@ -35,14 +35,17 @@ func authenticate(m chat1.MsgSummary) { @@ -35,14 +35,17 @@ func authenticate(m chat1.MsgSummary) {
k.SendMessageByConvID(m.ConvID, "Please remember to delete your message after we have authenticated!")
}
parts := strings.Split(m.Content.Text.Body, " ")
if len(parts) != 3 && len(parts) != 2 {
if len(parts) != 4 && len(parts) != 3 && len(parts) != 2 {
k.SendMessageByConvID(m.ConvID, "Invalid input for command authenticate. Requires username and password. This information is not stored in keybase, or logged. %+v", len(parts))
return
}
var username, password, tok string
if len(parts) == 3 {
if len(parts) > 2 {
username = parts[1]
password = parts[2]
if len(parts) == 4 {
tok = parts[3]
}
} else {
tok = parts[1]
}

7
login.go

@ -8,13 +8,15 @@ import ( @@ -8,13 +8,15 @@ import (
"golang.org/x/oauth2"
)
var mfaCode string
func noDevice(ctx context.Context, devices []tesla.Device) (d tesla.Device, passcode string, err error) {
return tesla.Device{}, "", nil
return devices[0], mfaCode, nil
}
func login(ctx context.Context, username string, password string, tok string) (string, error) {
var client *tesla.Client
var err error
if tok != "" {
if username == "" {
client, err = tesla.NewClient(
ctx,
tesla.WithToken(&oauth2.Token{
@ -22,6 +24,7 @@ func login(ctx context.Context, username string, password string, tok string) (s @@ -22,6 +24,7 @@ func login(ctx context.Context, username string, password string, tok string) (s
}),
)
} else {
mfaCode = tok
client, err = tesla.NewClient(
ctx,
tesla.WithMFAHandler(noDevice),

Loading…
Cancel
Save