Add token support?
This commit is contained in:
15
login.go
15
login.go
@ -5,17 +5,9 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/bogosj/tesla"
|
"github.com/bogosj/tesla"
|
||||||
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func selectDevice(ctx context.Context, devices []tesla.Device) (d tesla.Device, passcode string, err error) {
|
|
||||||
d = devices[0]
|
|
||||||
|
|
||||||
passcode = "000000"
|
|
||||||
if err != nil {
|
|
||||||
return tesla.Device{}, "", err
|
|
||||||
}
|
|
||||||
return d, passcode, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func login(ctx context.Context, username string, password string) (string, error) {
|
func login(ctx context.Context, username string, password string) (string, error) {
|
||||||
defer log.PanicSafe()
|
defer log.PanicSafe()
|
||||||
@ -23,7 +15,10 @@ func login(ctx context.Context, username string, password string) (string, error
|
|||||||
log.LogDebug("Creating client for %+v", username)
|
log.LogDebug("Creating client for %+v", username)
|
||||||
client, err := tesla.NewClient(
|
client, err := tesla.NewClient(
|
||||||
ctx,
|
ctx,
|
||||||
tesla.WithMFAHandler(selectDevice),
|
tesla.WithToken(&oauth2.Token{
|
||||||
|
AccessToken: username,
|
||||||
|
RefreshToken: password,
|
||||||
|
}),
|
||||||
tesla.WithCredentials(username, password),
|
tesla.WithCredentials(username, password),
|
||||||
)
|
)
|
||||||
log.LogDebug("Created client for %+v", username)
|
log.LogDebug("Created client for %+v", username)
|
||||||
|
|||||||
Reference in New Issue
Block a user