Jump to content

UnifiPresence authentication issues with UniFi OS 3.2.7


SamM
Go to solution Solved by bpwwer,

Recommended Posts

Posted

My CK2-Plus recently updated to UniFi OS 3.2.7.  Unfortunately it appears that Unifi has introduced an expiration to their authentication tokens, resulting in UnifiPresence resetting all presence nodes to 0.  The only workaround that I've found so far is to manually restart the nodeserver every couple of hours.

I'm curious if anybody else is experiencing this issue.  And whether there is anybody available to help support this node server.   Some notes...

Setting the nodeserver logging level to DEBUG only yields this detail:

2023-12-24 08:07:03,205 Thread-1119 udi_interface.node DEBUG node:setDriver: 80b989304495:80b989304495 No change in GV1's value
2023-12-24 08:07:03,205 Thread-1119 udi_interface INFO unifi_poly:update: update: 0

Creating a simple python script to mimic the nodeserver behavior, I have confirmed that the underlying python module that communicates with the Unifi controller does not properly handle 401 authentication failures that now appear ~2 hours after the initial connection.  It does do a brute force re-login process when certain connection exceptions are detected, but does not for this particular error condition:

2023-12-22 21:41:05,586 [WARNING] [pyunifi.controller] Received response 401 (Unauthorized)
2023-12-22 21:41:05,586 [WARNING] [pyunifi.controller] Failed to perform <function Controller._read at 0x1060760e0> due to Received response 401 (Unauthorized)

Since the python requests module can be configured to throw an exception when error responses like this are detected, the fix can be fairly simple.  However, I'm not currently set up to install and confirm nodeserver changes with PG3. 

-Sam

 

 

 

Posted

Some more details while investigating the issue that I'm having with the UnifiPresence nodeserver...

Unifi does not supply/support a python API into their controllers.  Instead, members of the user community have created various modules to communicate with Unifi's web API.  The modules are all very similar, including the fact that they are not regularly maintained, and make various assumptions that have worked okay to this point.  Unfortunately, none appear to properly handle the 401 responses.

UnifiPresence currently has the controller piece of this copied into its source:  https://github.com/NickWaterton/Unifi-websocket-interface That module has not been updated in a few years.

I have also investigated this module, since it has more recent updates (almost 2 years ago): https://github.com/finish06/pyunifi.

Both solutions make use of a python requests session, with attempts to re-login when exceptions are detected. 

-Sam

Posted

As I have found this nodeserver valuable in some of my programs, I've been investigating and testing a fix for this issue.  However, it appears that I don't have permissions to create a branch and/or pull request to assist with pushing/reviewing a potential fix. 

Based on prior discussion, the original owner/maintainer is unable to continue maintenance of this nodeserver:

From that discussion, @bpwwer had permissions to push a fix.  Going forward, is there a better method for nodeservers who no longer have an active owner?  Do we need somebody to take ownership in order to address issues and/or make general improvements as needed?

With that being said, I've also been exploring some basic fixes that would/could make this nodeserver fit my needs even better.

-Sam

Posted

Yes, I own the repository.  And I can grant permissions to it, but because of the way PG3 works, I either have to update the store entry or hand that off to someone else as only one person can "own" the store entry.

There are a number of node servers, like this one where the original author simply abandoned them.  I did the conversions to make them work on PG3 but beyond that, I can't really update/improve or even really debug them.

You should be able to make pull requests, there's nothing in the repository that would prevent that.  You should be able to fork the repository, make changes to your fork and start a pull request for those changes.

Posted

Thanks @bpwwer - I've created a fork with my changes, and started pull request https://github.com/UniversalDevicesInc-PG3/udi-presenceUnifi-nodeserver/pull/3.  If you don't see any issues with it, please consider merging that in and updating the store as needed.

Though I made a number of other changes to my dev version of the node server, I'm only pushing those necessary to address the issue at hand.  As I see several things that could be improved going forward, I would be interested in taking over ownership if that is helpful. 

Thanks again,

Sam

  • Like 1
  • Solution
Posted

I accepted the pull request so it should be updated now.  However, I don't own the node server so I can't update the store entry. 

  • Thanks 2
Posted

I updated my production node server on Friday after you merged the pull request.  It has been working flawlessly since.  Thanks again @bpwwer.

-Sam

Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371.4k
×
×
  • Create New...