Example #1
0
        public static string LoginToLogitech(string email, string password, string ipAddress, int harmonyPort)
        {
            string userAuthToken = HarmonyLogin.GetUserAuthToken(email, password);

            if (string.IsNullOrEmpty(userAuthToken))
            {
                throw new Exception("Could not get token from Logitech server.");
            }

            File.WriteAllText("UserAuthToken", userAuthToken);

            var authentication = new HarmonyAuthenticationClient(ipAddress, harmonyPort);

            string sessionToken = authentication.SwapAuthToken(userAuthToken);

            if (string.IsNullOrEmpty(sessionToken))
            {
                throw new Exception("Could not swap token on Harmony Hub.");
            }

            File.WriteAllText("SessionToken", sessionToken);

            Console.WriteLine("Date Time : {0}", DateTime.Now);
            Console.WriteLine("User Token: {0}", userAuthToken);
            Console.WriteLine("Sess Token: {0}", sessionToken);

            return(sessionToken);
        }
Example #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string loginnn = HarmonyLogin.LoginToLogitech("*****@*****.**", "fth123fth", "192.168.2.194", 5222);

            HarmonyHub.Device dev = new Device();

            HarmonyHub.Activity ac = new Activity();
        }
Example #3
0
        public ActionResult Login(AuthModels.Login model)
        {
            if (ModelState.IsValid)
            {
                string token = null;
                try
                {
                    token = HarmonyLogin.GetUserAuthToken(model.Username, model.Password);
                }
                catch { }

                if (string.IsNullOrEmpty(token))
                {
                    ModelState.AddModelError("Username", "Invalid username or password");
                }

                if (ModelState.IsValid)
                {
                    using (var manager = new Manager())
                    {
                        var user = manager.Users
                                   .FirstOrDefault(o => o.HarmonyUsername == model.Username);

                        if (user == null)
                        {
                            user = new User()
                            {
                                HarmonyUsername = model.Username
                            };
                        }

                        user.HarmonyPassword = "";
                        user.HarmonyToken    = token;
                        user.AlexaToken      = RandomString(50);
                        user.AlexaUserID     = "";
                        user.Hostname        = model.Hostname;

                        manager.SaveChanges();

                        string url = ConfigurationManager.AppSettings["AuthUrl"]
                                     + "#state=" + Url.Encode(model.State)
                                     + "&access_token=" + Url.Encode(user.AlexaToken)
                                     + "&token_type=Bearer";

                        return(Redirect(url));
                    }
                }
            }

            return(View(model));
        }