type userHashBody struct {
Properties struct {
AuthMethod string `json:"AuthMethod"`
SiteName string `json:"SiteName"`
RpsTicket string `json:"RpsTicket"`
}
RelyingParty string `json:"RelyingParty"`
TokenType string `json:"TokenType"`
}
type userHashResponse struct {
IssueInstant string `json:"IssueInstant"`
NotAfter string `json:"NotAfter"`
Token string `json:"Token"`
DisplayClaims struct {
Xui []struct {
Uhs string `json:"uhs"`
}
}
}
type XSTSTokenBody struct {
Properties struct {
SandboxId string `json:"SandboxId"`
UserTokens []string `json:"UserTokens"`
}
RelyingParty string `json:"RelyingParty"`
TokenType string `json:"TokenType"`
}
type XSTSTokenResponse struct {
IssueInstant time.Time `json:"IssueInstant"`
NotAfter time.Time `json:"NotAfter"`
Token string `json:"Token"`
DisplayClaims struct {
Xui []struct {
Uhs string `json:"uhs"`
} `json:"xui"`
}
}
type BearerTokenBody struct {
IdentityToken string `json:"identityToken"`
EnsureLegacyEnabled bool `json:"ensureLegacyEnabled"`
}
type BearerTokenResponse struct {
Username string `json:"username"`
Roles []interface{} `json:"roles"`
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
}```
#index out of range [0] with length 0
32 messages · Page 1 of 1 (latest)
func getUserHash(authToken string) (string, string) {
var userHashResponse userHashResponse
var userHashBody = userHashBody{
Properties: struct {
AuthMethod string `json:"AuthMethod"`
SiteName string `json:"SiteName"`
RpsTicket string `json:"RpsTicket"`
}{AuthMethod: "RPS", SiteName: "user.auth.xboxlive.com", RpsTicket: authToken},
RelyingParty: "http://auth.xboxlive.com",
TokenType: "JWT",
}
body, _ := json.Marshal(userHashBody)
if resp, err := http.Post("https://user.auth.xboxlive.com/user/authenticate", "application/json", bytes.NewBuffer(body)); err != nil {
log.Fatal(err)
} else {
defer resp.Body.Close()
resp.Header.Set("Accept", "application/json")
body, _ := io.ReadAll(resp.Body)
json.Unmarshal(body, &userHashResponse)
UserHash := userHashResponse.DisplayClaims.Xui[0].Uhs
UserToken := userHashResponse.Token
return UserHash, UserToken
}
return "", ""
}
you tried to access a slice with has 0 elements in it
without any line numbers it's hard to say
you should make sure the slice is at least length of 1 before accessing it
UserHash := userHashResponse.DisplayClaims.Xui[0].Uhs
guessing this line where Xui is a slice of 0
i see that's your question, sadly i do not have knowledge with xbl api to help on that
Am I dong it wrong with the struct or is it the api response?
{
"Properties": {
"SandboxId": "RETAIL",
"UserTokens": [
"TOKEN_HERE_FROM_PREVIOUS_STEP"
]
},
"RelyingParty": "rp://api.minecraftservices.com/",
"TokenType": "JWT"
}
that should be the userHashBody
Is it right?
@silent owl
{
"IssueInstant": "2021-02-07T21:41:03.6735105Z",
"NotAfter": "2021-02-08T13:41:03.6735105Z",
"Token": "SAVE_THIS_TOKEN",
"DisplayClaims": {
"xui": [
{
"uhs": "SAME_USER_HASH_AS_BEFORE"
}
]
}
}
that's the response
you could try printing the raw premarshal json results responses
hmm seems like that not an api issue then, xui is present in the response but it's not marshalled
you dont need to tag me every response, i muted this server for pings anyways
i will be available on my own terms
is that the expected response, or the response you got
you havent shown what is the response you actually got
yes that's what's necessary to understand who's wrong here
body, _ := io.ReadAll(resp.Body)
you are also silencing an error, errors useful for debugging might be lost in it
2022/10/04 22:06:59 Status Code: 400 Bad Request
nope
my request is bad
idrk what's wrong my request tho...
you can also echo out the body and see if the json you sent is what you expected to be