Update for new roblox login

This commit is contained in:
itzaname 2018-10-09 20:57:50 -04:00
parent 26038aec3a
commit 9db9723808

View File

@ -1,10 +1,11 @@
package roblox package roblox
import ( import (
"bytes"
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"net/http/cookiejar" "net/http/cookiejar"
"net/url"
) )
// Session struct for roblox login session data and members // Session struct for roblox login session data and members
@ -21,17 +22,11 @@ func New(username, password string) (*Session, error) {
Jar: cookieJar, Jar: cookieJar,
} }
v := url.Values{}
v.Set("username", username)
v.Set("password", password)
v.Set("submitLogin", "Log In")
v.Set("ReturnUrl", "")
session := Session{0, username, client} session := Session{0, username, client}
resp, err := client.PostForm("https://www.roblox.com/newlogin", v) err := session.Login(username, password)
if resp.StatusCode != 200 { if err != nil {
return &session, fmt.Errorf("Messaged send failed. Status %d", resp.StatusCode) return nil, fmt.Errorf("Failed to login: %s", err)
} }
info, err := session.GetUserInfo() info, err := session.GetUserInfo()
@ -43,3 +38,43 @@ func New(username, password string) (*Session, error) {
return &session, err return &session, err
} }
func (s *Session) Login(username, password string) error {
details := struct {
Ctype string `json:"ctype"`
Cvalue string `json:"cvalue"`
Password string `json:"password"`
}{
"Username",
username,
password,
}
payload, err := json.Marshal(&details)
if err != nil {
return err
}
resp, err := s.client.Post("https://auth.roblox.com/v1/login", "application/json", bytes.NewBuffer(payload))
if err != nil {
return err
}
resp.Body.Close()
if resp.StatusCode == 403 {
req, err := http.NewRequest("POST", "https://auth.roblox.com/v1/login", bytes.NewBuffer(payload))
req.Header.Set("X-Csrf-Token", resp.Header["X-Csrf-Token"][0])
req.Header.Set("Content-Type", "application/json")
resp, err := s.client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("Status %d", resp.StatusCode)
}
}
return nil
}