using refresh token now

This commit is contained in:
Samuel Walker 2024-10-29 05:55:36 -06:00
parent 664741d3b2
commit 4154fdeec9
2 changed files with 28 additions and 5 deletions

33
main.go
View File

@ -140,16 +140,39 @@ func main() {
}
}
os.MkdirAll(filepath.Join(dir, "minecraft_test"), 0755)
f, _ := os.OpenFile(filepath.Join(dir, "minecraft_test", "authentication.json"), os.O_CREATE|os.O_RDWR, 0755)
defer f.Close()
data, _ = json.Marshal(auth.Access)
f.Write(data)
} else {
f, _ := os.OpenFile(filepath.Join(dir, "minecraft_test", "authentication.json"), os.O_CREATE|os.O_RDWR, 0755)
data, _ := io.ReadAll(f)
json.Unmarshal(data, &auth.Access)
resp, err := http.PostForm("https://login.microsoftonline.com/consumers/oauth2/v2.0/token", url.Values{
"client_id": {client_id},
"grant_type": {"refresh_token"},
"refresh_token": {auth.Access.Refresh_token},
"scope": {"XboxLive.SignIn XboxLive.offline_access"},
})
if err != nil {
fmt.Printf("Authentication Request Error: %s\n", err)
}
defer resp.Body.Close()
//if resp.StatusCode != 200 {
// fmt.Printf("Authentication Request Error: %s\n", resp.Status)
//}
data, _ = io.ReadAll(resp.Body)
authResp := authenticationResp{}
json.Unmarshal(data, &authResp)
if authResp.Error == "" {
fmt.Printf("Authenticated!\n")
auth.Access = authResp
}
}
os.MkdirAll(filepath.Join(dir, "minecraft_test"), 0755)
f, _ := os.OpenFile(filepath.Join(dir, "minecraft_test", "authentication.json"), os.O_CREATE|os.O_RDWR, 0755)
defer f.Close()
data, _ := json.Marshal(auth.Access)
f.Write(data)
req, _ := json.Marshal(xboxAuthRequest{Properties: xboxAuthProperties{AuthMethod: "RPS", SiteName: "user.auth.xboxlive.com", RpsTicket: "d=" + auth.Access.Access_token}, RelyingParty: "http://auth.xboxlive.com", TokenType: "JWT"})
client := http.Client{}
httpReq, _ := http.NewRequest("POST", "https://user.auth.xboxlive.com/user/authenticate", bytes.NewBuffer(req))

BIN
minecraft

Binary file not shown.