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.
35 lines
694 B
35 lines
694 B
package main |
|
|
|
import ( |
|
"context" |
|
"encoding/json" |
|
|
|
"github.com/bogosj/tesla" |
|
) |
|
|
|
func noDevice(ctx context.Context, devices []tesla.Device) (d tesla.Device, passcode string, err error) { |
|
return tesla.Device{}, "", nil |
|
} |
|
func login(ctx context.Context, username string, password string) (string, error) { |
|
client, err := tesla.NewClient( |
|
ctx, |
|
tesla.WithMFAHandler(noDevice), |
|
tesla.WithCredentials(username, password), |
|
) |
|
if err != nil { |
|
log.LogErrorType(err) |
|
return "", err |
|
} |
|
|
|
t, err := client.Token() |
|
if err != nil { |
|
log.LogErrorType(err) |
|
return "", err |
|
} |
|
ret, err := json.Marshal(t) |
|
if err != nil { |
|
log.LogErrorType(err) |
|
return "", err |
|
} |
|
return string(ret), nil |
|
}
|
|
|