Skip to content

Commit

Permalink
Fixed issue getting tesla token on username and password login
Browse files Browse the repository at this point in the history
Issue: bogosj#83
  • Loading branch information
evenmun committed May 18, 2023
1 parent 30788c9 commit d9fd2f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,29 @@ func (a *auth) login(ctx context.Context, username, password string) (*http.Resp
v["captcha"] = []string{solution}
}

v.Set("_phase", "authenticate")
v.Set("_process", "1")

req, err = http.NewRequestWithContext(ctx, http.MethodPost, a.AuthURL, strings.NewReader(v.Encode()))
if err != nil {
return nil, nil, fmt.Errorf("new request: %w", err)
}

req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

for _, cookie := range res.Cookies() {
cookie := &http.Cookie{
Name: cookie.Name,
Value: cookie.Value,
}
req.AddCookie(cookie)
}

res, err = a.Client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("do request: %w", err)
}

return res, v, err
}

Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var OAuth2Config = &oauth2.Config{
ClientID: "ownerapi",
RedirectURL: "https://auth.tesla.com/void/callback",
Endpoint: oauth2.Endpoint{
AuthURL: "https://auth.tesla.com/oauth2/v3/authorize",
AuthURL: "https://auth.tesla.com/en_us/oauth2/v3/authorize",
TokenURL: "https://auth.tesla.com/oauth2/v3/token",
AuthStyle: oauth2.AuthStyleInParams,
},
Expand Down

0 comments on commit d9fd2f8

Please sign in to comment.