Add token auth

This commit is contained in:
2021-07-10 11:05:26 -04:00
parent 2132f1088c
commit 146b374060
2 changed files with 14 additions and 5 deletions

View File

@ -37,14 +37,19 @@ 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 {
if 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.")
return
}
log.LogDebug("Proper amount of parameters has been received, calling login()")
username := parts[1]
password := parts[2]
t, err := login(context.Background(), username, password)
var username, password, tok string
if len(parts) == 3 {
username = parts[1]
password = parts[2]
} else {
tok = parts[1]
}
t, err := login(context.Background(), username, password, tok)
if err != nil {
handleError(err, m, "There was an error logging in. Contact @rudi9719 for more information with code %+v")
return

View File

@ -5,16 +5,20 @@ import (
"encoding/json"
"github.com/bogosj/tesla"
"golang.org/x/oauth2"
)
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) {
func login(ctx context.Context, username string, password string, tok string) (string, error) {
client, err := tesla.NewClient(
ctx,
tesla.WithMFAHandler(noDevice),
tesla.WithToken(&oauth2.Token{
RefreshToken: tok,
}),
tesla.WithCredentials(username, password),
)
if err != nil {