Skip to content

Commit fac5b21

Browse files
committed
Fix Garmin login for some passwords #10
1 parent adb98ee commit fac5b21

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/garmin/auth.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ func (c *Client) getTicket(username, password string) (string, error) {
5959
csrf := core.Between(string(body), `name="_csrf" value="`, `"`)
6060

6161
// 3. Signin
62-
data := fmt.Sprintf("username=%s&password=%s&embed=true&_csrf=%s", username, password, csrf)
62+
data := fmt.Sprintf(
63+
"username=%s&password=%s&embed=true&_csrf=%s",
64+
url.QueryEscape(username), url.QueryEscape(password), csrf,
65+
)
6366

6467
req, err := http.NewRequest("POST", url2, strings.NewReader(data))
6568
if err != nil {
@@ -82,6 +85,9 @@ func (c *Client) getTicket(username, password string) (string, error) {
8285

8386
ticket := core.Between(string(body), `embed?ticket=`, `"`)
8487
if ticket == "" {
88+
if msg := core.Between(string(body), `class="error">`, `<`); msg != "" {
89+
return "", errors.New("garmin: " + msg)
90+
}
8591
return "", errors.New("garmin: can't find ticket")
8692
}
8793

0 commit comments

Comments
 (0)