From b846ebe57518bab3ea873d72e102a43831da6f58 Mon Sep 17 00:00:00 2001 From: itzaname Date: Thu, 17 Jan 2019 20:56:07 -0500 Subject: [PATCH] Change to cookie login --- session.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/session.go b/session.go index cb65171..c24ed37 100644 --- a/session.go +++ b/session.go @@ -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 -} +}*/