Beispiel #1
0
        /// <summary>
        /// Authenticate with Xbox Live #1<br/>
        /// Now you're able to authenticate with XBL via your <paramref name="access_token"/>.
        /// </summary>
        /// <param name="access_token">The <b>AccessToken</b> from <see cref="Microsoft.Identity.Client.AuthenticationResult"/>.</param>
        /// <returns></returns>
        private xbox.TokenResponse XboxLiveAuthenticate(string access_token)
        {
            xbox.AuthenticationRequest request = new()
            {
                Properties = new xbox.AuthenticationProperties
                {
                    AuthMethod = xbox.AuthMethod.RPS,
                    SiteName   = "user.auth.xboxlive.com",
                    RpsTicket  = $"d={access_token}"
                },
                RelyingParty = "http://auth.xboxlive.com",
                TokenType    = xbox.TokenType.JWT
            };
            var rstr = JsonSerializer.Serialize(request);

            Logger.Debug(rstr);
            var responseStr = NetHandler.SendPostRequest(AuthLinks.XblAuthLink, AuthSettings.UserAgent, "application/json", rstr, "Accept", "application/json", "x-xbl-contract-version", "1");

            xbox.TokenResponse response = JsonSerializer.Deserialize <xbox.TokenResponse>(responseStr);

            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// Authenticate with Xbox Live #2<br/>
        /// After getting the <see cref="xbox.TokenResponse"/>, you'll be able to authenticate with XSTS.
        /// </summary>
        /// <param name="xbl_token">The <b>Token</b> value of <see cref="xbox.TokenResponse"/>.</param>
        private xbox.TokenResponse XSTSAuthenticate(string xbl_token)
        {
            xbox.AuthenticationRequest request = new()
            {
                Properties = new xbox.AuthenticationProperties
                {
                    SandboxId  = "RETAIL",
                    UserTokens = new List <string>()
                    {
                        xbl_token
                    }
                },
                RelyingParty = "rp://api.minecraftservices.com/",
                TokenType    = xbox.TokenType.JWT
            };

            xbox.TokenResponse response = JsonSerializer.Deserialize <xbox.TokenResponse>(NetHandler.SendPostRequest(AuthLinks.XstsAuthLink, AuthSettings.UserAgent, "application/json", JsonSerializer.Serialize(request), "Accept", "application/json"));

            return(response);
        }

        #endregion
    }