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 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
@ -16,18 +15,25 @@ type Session struct {
} }
// New create a new session and logs in with provided data // 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) 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{ client := &http.Client{
Jar: cookieJar, Jar: cookieJar,
} }
session := Session{0, username, client} session := Session{0, username, client}
err := session.Login(username, password) /*err := session.Login(username, password)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to login: %s", err) return nil, fmt.Errorf("Failed to login: %s", err)
} }*/
info, err := session.GetUserInfo() info, err := session.GetUserInfo()
if err != nil { if err != nil {
@ -39,7 +45,7 @@ func New(username, password string) (*Session, error) {
return &session, err return &session, err
} }
func (s *Session) Login(username, password string) error { /*func (s *Session) Login(username, password string) error {
details := struct { details := struct {
Ctype string `json:"ctype"` Ctype string `json:"ctype"`
Cvalue string `json:"cvalue"` Cvalue string `json:"cvalue"`
@ -54,14 +60,14 @@ func (s *Session) Login(username, password string) error {
return err 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 { if err != nil {
return err return err
} }
resp.Body.Close() resp.Body.Close()
if resp.StatusCode == 403 { 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("X-Csrf-Token", resp.Header["X-Csrf-Token"][0])
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
@ -77,4 +83,4 @@ func (s *Session) Login(username, password string) error {
} }
return nil return nil
} }*/