Exemplo n.º 1
0
        /// <summary>
        /// Xbox Live Authenticate
        /// </summary>
        /// <param name="loginResponse"></param>
        /// <returns></returns>
        public static XblAuthenticateResponse XblAuthenticate(Microsoft.LoginResponse loginResponse)
        {
            var request = new ProxiedWebRequest(xbl);

            request.UserAgent = userAgent;
            request.Accept    = "application/json";
            request.Headers.Add("x-xbl-contract-version", "0");

            var accessToken = loginResponse.AccessToken;

            if (Settings.LoginMethod == "browser")
            {
                // Our own client ID must have d= in front of the token or HTTP status 400
                // "Stolen" client ID must not have d= in front of the token or HTTP status 400
                accessToken = "d=" + accessToken;
            }

            string payload = "{"
                             + "\"Properties\": {"
                             + "\"AuthMethod\": \"RPS\","
                             + "\"SiteName\": \"user.auth.xboxlive.com\","
                             + "\"RpsTicket\": \"" + accessToken + "\""
                             + "},"
                             + "\"RelyingParty\": \"http://auth.xboxlive.com\","
                             + "\"TokenType\": \"JWT\""
                             + "}";
            var response = request.Post("application/json", payload);

            if (Settings.DebugMessages)
            {
                ConsoleIO.WriteLine(response.ToString());
            }
            if (response.StatusCode == 200)
            {
                string jsonString = response.Body;
                //Console.WriteLine(jsonString);

                Json.JSONData json     = Json.ParseJson(jsonString);
                string        token    = json.Properties["Token"].StringValue;
                string        userHash = json.Properties["DisplayClaims"].Properties["xui"].DataArray[0].Properties["uhs"].StringValue;
                return(new XblAuthenticateResponse()
                {
                    Token = token,
                    UserHash = userHash
                });
            }
            else
            {
                throw new Exception("XBL Authentication failed");
            }
        }
Exemplo n.º 2
0
        private static LoginResult MicrosoftLogin(Microsoft.LoginResponse msaResponse, out SessionToken session)
        {
            session = new SessionToken()
            {
                ClientID = Guid.NewGuid().ToString().Replace("-", "")
            };
            var ms = new XboxLive();
            var mc = new MinecraftWithXbox();

            try
            {
                var xblResponse = ms.XblAuthenticate(msaResponse);
                var xsts        = ms.XSTSAuthenticate(xblResponse); // Might throw even password correct

                string accessToken = mc.LoginWithXbox(xsts.UserHash, xsts.Token);
                bool   hasGame     = mc.UserHasGame(accessToken);
                if (hasGame)
                {
                    var profile = mc.GetUserProfile(accessToken);
                    session.PlayerName   = profile.UserName;
                    session.PlayerID     = profile.UUID;
                    session.ID           = accessToken;
                    session.RefreshToken = msaResponse.RefreshToken;
                    Settings.Login       = msaResponse.Email;
                    return(LoginResult.Success);
                }
                else
                {
                    return(LoginResult.NotPremium);
                }
            }
            catch (Exception e)
            {
                ConsoleIO.WriteLineFormatted("§cMicrosoft authenticate failed: " + e.Message);
                if (Settings.DebugMessages)
                {
                    ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
                }
                return(LoginResult.WrongPassword); // Might not always be wrong password
            }
        }