HueLibrary.Bridge.RegisterAsync C# (CSharp) Method

RegisterAsync() public method

Registers the application with the bridge and returns if the authorization succeeded.
public RegisterAsync ( ) : Task
return Task
        public async Task<bool> RegisterAsync()
        {
            try
            {
                using (var client = new HttpClient())
                {
                    string id = new Random().Next().ToString(); 
                    var response = await client.PostAsync(new Uri($"http://{Ip}/api"), 
                        new HttpStringContent($"{{\"devicetype\":\"HueLightController#{id}\"}}"));
                    string content = await response.Content.ReadAsStringAsync();
                    JArray json = JArray.Parse(content);
                    if (null != json.First["success"])
                    {
                        UserId = json.First["success"]["username"].ToString();
                        return true;
                    }
                }
            }
            catch (Exception)
            {
                return false; 
            }
            return false; 
        }