Exemplo n.º 1
0
        /// <summary>
        /// A Function to authenticate a player to Mojang's API. Username and Password must be valid. If the process was succesfull then you can access LastResponse to get any infromation available.
        /// </summary>
        /// <param name="username">The userame or email to Authenticate</param>
        /// <param name="password">The user's password for the current account</param>
        /// <param name="guid">A guid for the current machine</param>
        /// <returns>Returns true if the Authentication proccess was succefull.</returns>
        public static async Task <bool> Try(string username, string password, string guid)
        {
            var jsonRequest = new AuthenticateJSON
            {
                username    = username,
                password    = password,
                requestUser = true,
                clientToken = guid,
                agent       = new Agent
                {
                    name    = "Minecraft",
                    version = 1
                }
            };
            string responseString;

            try
            {
                responseString = await NetConnector.MakeRequest(jsonRequest, "https://authserver.mojang.com/authenticate");
            }
            catch
            {
                return(false);
            }

            lastResponse = JsonConvert.DeserializeObject <APIResponse>(responseString);
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Refreshes a valid accessToken. It can user to keep the user logged in.
        /// </summary>
        /// <param name="accessToken">The accessToken to be refreshed</param>
        /// <param name="requestUser">If true the user object will be returned</param>
        /// <param name="clientToken">This needs to be identical to the one used to obtain the accessToken in the first place. Leave empty if unknown</param>
        /// <returns>True if the Refreshed proccess was succefull.</returns>
        public static async Task <bool> Try(string accessToken, string clientToken, bool requestUser)
        {
            var jsonRequest = new Payload
            {
                accessToken = accessToken,
                clientToken = clientToken,
                requestUser = requestUser,
            };
            string responseString;

            try
            {
                responseString = await NetConnector.MakeRequest(jsonRequest, URL);
            }
            catch
            {
                return(false);
            }

            lastResponse = JsonConvert.DeserializeObject <APIResponse>(responseString);
            return(true);
        }