Allow login using basic single device mfaCode
This commit is contained in:
@ -9,7 +9,7 @@ func setupCommands() {
|
|||||||
Commands: []chat1.UserBotCommandInput{
|
Commands: []chat1.UserBotCommandInput{
|
||||||
{
|
{
|
||||||
Name: "authenticate",
|
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",
|
Usage: "email@example.com Pa$$w0rd",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -35,14 +35,17 @@ func authenticate(m chat1.MsgSummary) {
|
|||||||
k.SendMessageByConvID(m.ConvID, "Please remember to delete your message after we have authenticated!")
|
k.SendMessageByConvID(m.ConvID, "Please remember to delete your message after we have authenticated!")
|
||||||
}
|
}
|
||||||
parts := strings.Split(m.Content.Text.Body, " ")
|
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))
|
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
|
return
|
||||||
}
|
}
|
||||||
var username, password, tok string
|
var username, password, tok string
|
||||||
if len(parts) == 3 {
|
if len(parts) > 2 {
|
||||||
username = parts[1]
|
username = parts[1]
|
||||||
password = parts[2]
|
password = parts[2]
|
||||||
|
if len(parts) == 4 {
|
||||||
|
tok = parts[3]
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tok = parts[1]
|
tok = parts[1]
|
||||||
}
|
}
|
||||||
|
|||||||
7
login.go
7
login.go
@ -8,13 +8,15 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var mfaCode string
|
||||||
|
|
||||||
func noDevice(ctx context.Context, devices []tesla.Device) (d tesla.Device, passcode string, err error) {
|
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) {
|
func login(ctx context.Context, username string, password string, tok string) (string, error) {
|
||||||
var client *tesla.Client
|
var client *tesla.Client
|
||||||
var err error
|
var err error
|
||||||
if tok != "" {
|
if username == "" {
|
||||||
client, err = tesla.NewClient(
|
client, err = tesla.NewClient(
|
||||||
ctx,
|
ctx,
|
||||||
tesla.WithToken(&oauth2.Token{
|
tesla.WithToken(&oauth2.Token{
|
||||||
@ -22,6 +24,7 @@ func login(ctx context.Context, username string, password string, tok string) (s
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
mfaCode = tok
|
||||||
client, err = tesla.NewClient(
|
client, err = tesla.NewClient(
|
||||||
ctx,
|
ctx,
|
||||||
tesla.WithMFAHandler(noDevice),
|
tesla.WithMFAHandler(noDevice),
|
||||||
|
|||||||
Reference in New Issue
Block a user