-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauth.go
More file actions
32 lines (27 loc) · 703 Bytes
/
auth.go
File metadata and controls
32 lines (27 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package vrchat
import (
"fmt"
)
// Authenticate authenticates the client with the VRChat API
func (c *Client) Authenticate(username, password, totp string) error {
c.client.SetHeaders(map[string]string{
"User-Agent": "vrchat-go/0.0.0 mayo@linux.com",
"Accept": "application/json",
"Content-Type": "application/json",
})
resp, err := c.client.R().
SetBasicAuth(username, password).
SetBody(map[string]string{
"code": totp,
}).
Post("/auth/twofactorauth/totp/verify")
if err != nil {
return err
}
if resp.StatusCode() != 200 {
return fmt.Errorf("failed to authenticate: %s", resp.String())
}
cookies := resp.Cookies()
c.client.SetCookies(cookies)
return nil
}