private MinecraftLoginResult LoginUsingUsernameAndPassword(MinecraftUser user)
        {
            YggdrasilAuthRequest request = new YggdrasilAuthRequest(user.Username, user.Password, GetClientToken());
            YggdrasilAuthResponse response = SubmitRequest<YggdrasilAuthResponse, YggdrasilAuthRequest>(Yggdrasil.AUTH_LOGIN_URL, request);

            user.AuthToken = response.AccessToken;
            user.Profiles = response.AvailableProfiles.Select(p => new MinecraftProfile (p.Id, p.Name)).ToList();
            user.SelectedProfile = user.Profiles.First (p => p.Id == response.SelectedProfile.Id);

            return MinecraftLoginResult.Success;
        }
        private MinecraftLoginResult LoginUseingTokens(MinecraftUser user)
        {
            YggdrasilRefreshRequest request = new YggdrasilRefreshRequest(user.AuthToken, GetClientToken());
            YggdrasilRefreshResponse response = SubmitRequest<YggdrasilRefreshResponse, YggdrasilRefreshRequest>(Yggdrasil.AUTH_REFRESH_URL, request);

            user.AuthToken = response.AccessToken;
            user.SelectedProfile = new MinecraftProfile (response.SelectedProfile.Id, response.SelectedProfile.Name);
            user.Profiles = new List<MinecraftProfile>() { user.SelectedProfile };

            return MinecraftLoginResult.Success;
        }
        /// <summary>
        /// Allows to login to a premium Minecraft account using the Yggdrasil authentication scheme.
        /// </summary>
        /// <param name="user">Login</param>
        /// <param name="pass">Password</param>
        /// <param name="accesstoken">Will contain the access token returned by Minecraft.net, if the login is successful</param>
        /// <param name="uuid">Will contain the player's UUID, needed for multiplayer</param>
        /// <returns>Returns the status of the login (Success, Failure, etc.)</returns>
        public static MinecraftLoginResult GetLogin(ref string user, string pass, ref string accesstoken, ref string uuid)
        {
            MinecraftUser userObj = new MinecraftUser (user, pass);
            MinecraftLoginResult result = mcAuthProvider.Login (userObj);

            if (result == MinecraftLoginResult.Success)
            {
                accesstoken = userObj.AuthToken;
                uuid = userObj.SelectedProfile.Id;
            }

            return result;
        }
        public MinecraftLoginResult Login(MinecraftUser user)
        {
            MinecraftLoginResult result;
            if (!string.IsNullOrWhiteSpace (user.Username) && !string.IsNullOrWhiteSpace (user.Password))
                result = LoginUsingUsernameAndPassword (user);
            else if (!string.IsNullOrWhiteSpace (user.AuthToken))
                result = LoginUseingTokens (user);
            else
                throw new InvalidOperationException ("Can't Login without an given Username/Password- or AccessToken/ClientToken-combination");

            if (result == MinecraftLoginResult.Success && user.Profiles.Count <= 0)
                    result = MinecraftLoginResult.NotPremium;

            return result;
        }
 public void Logout(MinecraftUser login)
 {
     provider.Logout (login);
 }
        /// <summary>
        /// Check session using the Yggdrasil authentication scheme. Allow to join an online-mode server
        /// </summary>
        /// <param name="user">Username</param>
        /// <param name="accesstoken">Session ID</param>
        /// <param name="serverhash">Server ID</param>
        /// <returns>TRUE if session was successfully checked</returns>
        public static bool SessionCheck(string uuid, string accesstoken, string serverhash)
        {
            MinecraftUser userObj = new MinecraftUser(accesstoken);
            userObj.SelectedProfile = new MinecraftProfile(uuid, uuid);

            return mcSessionProvider.JoinServer(userObj, new MinecraftServer(serverhash, IPAddress.Any));
        }
 public bool JoinServer(MinecraftUser user, MinecraftServer server)
 {
     YggdrasilSessionJoinRequest request = new YggdrasilSessionJoinRequest (user.AuthToken, user.SelectedProfile.Id, server.ServerId);
     string response = SubmitRequest<YggdrasilSessionJoinRequest> (Yggdrasil.SESSION_JOIN_URL, request);
     return (response == "");
 }
 //TODO: Implement Logout
 public void Logout(MinecraftUser user)
 {
     throw new NotImplementedException ();
 }