Change to cookie login

This commit is contained in:
itzaname 2019-01-17 20:56:07 -05:00
parent 9db9723808
commit b846ebe575

View File

@ -1,11 +1,10 @@
package roblox
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/http/cookiejar"
"net/url"
)
// Session struct for roblox login session data and members
@ -16,18 +15,25 @@ type Session struct {
}
// New create a new session and logs in with provided data
func New(username, password string) (*Session, error) {
func New(username, cookie string) (*Session, error) {
cookieJar, _ := cookiejar.New(nil)
rbxCookie := []*http.Cookie{&http.Cookie{
Name: ".ROBLOSECURITY",
Value: cookie,
}}
// url.Parse("http://www.roblox.com") // http://api.roblox.com
cookieJar.SetCookies(&url.URL{Scheme: "http", Host: "www.roblox.com"}, rbxCookie)
cookieJar.SetCookies(&url.URL{Scheme: "http", Host: "api.roblox.com"}, rbxCookie)
client := &http.Client{
Jar: cookieJar,
}
session := Session{0, username, client}
err := session.Login(username, password)
/*err := session.Login(username, password)
if err != nil {
return nil, fmt.Errorf("Failed to login: %s", err)
}
}*/
info, err := session.GetUserInfo()
if err != nil {
@ -39,7 +45,7 @@ func New(username, password string) (*Session, error) {
return &session, err
}
func (s *Session) Login(username, password string) error {
/*func (s *Session) Login(username, password string) error {
details := struct {
Ctype string `json:"ctype"`
Cvalue string `json:"cvalue"`
@ -54,14 +60,14 @@ func (s *Session) Login(username, password string) error {
return err
}
resp, err := s.client.Post("https://auth.roblox.com/v1/login", "application/json", bytes.NewBuffer(payload))
resp, err := s.client.Post("https://auth.roblox.com/v2/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, err := http.NewRequest("POST", "https://auth.roblox.com/v2/login", bytes.NewBuffer(payload))
req.Header.Set("X-Csrf-Token", resp.Header["X-Csrf-Token"][0])
req.Header.Set("Content-Type", "application/json")
@ -77,4 +83,4 @@ func (s *Session) Login(username, password string) error {
}
return nil
}
}*/