michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
412 stars 114 forks source link

Q42.HueApi.HueException: 'unauthorized user' while calling DeleteWhiteListEntryAsync #216

Closed Gforse12 closed 4 years ago

Gforse12 commented 4 years ago

Recently i've updated the Q42.HueApi library from 3.8.3.0 to 3.15.1.0. But now when i try to delete a user i get the exception Q42.HueApi.HueException: 'unauthorized user'.

I can however control all lights and groups.

Callstack:

This exception was originally thrown at this call stack:
    Q42.HueApi.HueClient.DeleteWhiteListEntryAsync(string)
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    System.Runtime.CompilerServices.TaskAwaiter<TResult>.GetResult()
    AppName.HueBridge_Settings.btnRemoveWhitelist_Click(Object, System.Windows.RoutedEventArgs) in HueBridge_Settings.xaml.vb

My Code:

If Not HueLocal.SelectedBridge Is Nothing AndAlso Not HueLocal.SelectedBridge.EntertainmentClient.LocalHueClient Is Nothing AndAlso Not cbWhitelist.SelectedItem Is Nothing Then
    'Check if we are not removing ourselfs
    If HueLocal.SelectedBridge.EntertainmentInfo.Username = CType(cbWhitelist.SelectedItem, WhiteList).Id Then
        localMain.ShowMessageDialog("Cannot remove this application form the whitelist.")
        Exit Sub
    End If
    'Now double check with user and then remove.
    If Await localMain.ShowAskingMessageDialog("Are you sure you want the remove device [ " & CType(cbWhitelist.SelectedItem, WhiteList).Name & " ] from the whitelist?") = MahApps.Metro.Controls.Dialogs.MessageDialogResult.Affirmative Then
        If Await HueLocal.SelectedBridge.EntertainmentClient.LocalHueClient.DeleteWhiteListEntryAsync(CType(cbWhitelist.SelectedItem, WhiteList).Id) Then
            UpdateUI()
            localMain.ShowMessageDialog("Succesfully removed application [ " & CType(cbWhitelist.SelectedItem, WhiteList).Name & " ] from the whitelist.")
            Log.Message(LogLevel.Info, "Succesfully removed application [ " & CType(cbWhitelist.SelectedItem, WhiteList).Name & " ] from the whitelist.")
        Else
            localMain.ShowMessageDialog("Failed to removed application [ " & CType(cbWhitelist.SelectedItem, WhiteList).Name & " ] from the whitelist.")
            Log.Message(LogLevel.Warning, "Failed to removed application [ " & CType(cbWhitelist.SelectedItem, WhiteList).Name & " ] from the whitelist.")
        End If
    End If
End If

Hue bridge is running software version 1937045000, Api version 1.36.0 and application is compiled as 4.7.2

michielpost commented 4 years ago

Hue changed the permission level of this API. Since bridge API level 1.31.0 it's no longer possible to delete a user using the local API. If I understand the API docs correctly, it's only possible using the Cloud/Remote API. See the docs: https://developers.meethue.com/develop/hue-api/7-configuration-api/#del-user-from-whitelist

Gforse12 commented 4 years ago

Ah thanks, that explains a lot. Since we use the API offline i will remove this function.