janbar / noson-app

The essential to control music from your SONOS devices on Linux platforms
GNU General Public License v3.0
335 stars 28 forks source link

Spotifiy: tokenRefreshRequired #197

Open hzulla opened 1 year ago

hzulla commented 1 year ago

(Hi, once again, thanks for Noson.)

On two different computers where I installed Noson a long time ago, Spotify now complains: "tokenRefreshRequired".

I have no idea what to do here. The only solution I found was to remove Spotify and re-add it to Noson. After that, things worked again.

scottwallacesh commented 1 year ago

I have the same issue. Re-adding it only lasts for a short period however before it's needed to remove and re-add the Spotify service.

My instance of Noson is installed via Snap and, I suspect, it's not able to store or retrieve the token for some reason.

I've no idea if these logs are relevant or not:

installing thumbnails cache in folder "/home/scott/snap/noson/563/.local/share/janbar/io.github.janbar.noson/QML/OfflineStorage"
propsReply "An AppArmor policy prevents this sender from sending this message to this recipient; type=\"method_call\", sender=\":1.21974\" (uid=1000 pid=1138830 comm=\"/snap/noson/563/usr/lib/x86_64-linux-gnu/noson/nos\" label=\"snap.noson.noson (enforce)\") interface=\"org.freedesktop.DBus.Properties\" member=\"GetAll\" error name=\"(unset)\" requested_reply=\"0\" destination=\"org.freedesktop.NetworkManager\" (uid=0 pid=1506 comm=\"/usr/sbin/NetworkManager --no-daemon \" label=\"unconfined\")"
nmReply "An AppArmor policy prevents this sender from sending this message to this recipient; type=\"method_call\", sender=\":1.21974\" (uid=1000 pid=1138830 comm=\"/snap/noson/563/usr/lib/x86_64-linux-gnu/noson/nos\" label=\"snap.noson.noson (enforce)\") interface=\"org.freedesktop.NetworkManager\" member=\"GetDevices\" error name=\"(unset)\" requested_reply=\"0\" destination=\"org.freedesktop.NetworkManager\" (uid=0 pid=1506 comm=\"/usr/sbin/NetworkManager --no-daemon \" label=\"unconfined\")"
"Object path cannot be empty"
    [...]
registerContent: 0x5580453239f0 ()
loadContent: 0x5580453239f0 ()
(SONOS)SSLSessionFactory: SSL engine initialized
(SONOS)WSResponse: server error (500)
qml: Fault: tokenRefreshRequired

The last time anything was written to the QML storage was December 5th:

$ find /home/scott/snap/noson/563/.local/share/janbar/io.github.janbar.noson/QML/OfflineStorage | xargs ls -latrd | tail -3
drwxrwxr-x  2 scott scott   4096 Dec  5 08:20 /home/scott/snap/noson/563/.local/share/janbar/io.github.janbar.noson/QML/OfflineStorage/thumbnailer/prepared
-rw-------  1 scott scott    157 Dec  5 08:20 /home/scott/snap/noson/563/.local/share/janbar/io.github.janbar.noson/QML/OfflineStorage/thumbnailer/data8/9/35mw3dj9.d
drwxrwxr-x  2 scott scott   4096 Dec  5 08:20 /home/scott/snap/noson/563/.local/share/janbar/io.github.janbar.noson/QML/OfflineStorage/thumbnailer/data8/9
jasetthomas commented 1 year ago

First, thanks to the developer for this product - its the only one I have managed to get working on Linux.

I just rebuilt the latest src (Manjaro/linux with linux-zen kernel) and can confirm the problem is also present (in non-snap install)

Can confirm that it asks for token refresh quite a lot - perhaps it is only a default token for 1 hour ?

Some logs...

rc:/controls2/components/MusicRow.qml:101:13: QML Image: Error transferring http://192.168.1.3:1400/getaa?s=1&u=x-sonos-spotify%3Aspotify%253atrack%253a2zivGRWrgRZ3PZI4ZEhFVO%3Fsid%3D12%26flags%3D8224%26sn%3D1 - server replied: Not Found qml: Set queue position view at 27 qml: Set queue position view at 28 qml: Set queue position view at 30 qml: Set queue position view at 33 playerEventCB: container [Q:0] has being updated to 12 loadContent: 0x55e307bdc290 (Q:0) playerEventCB: container [Q:0] has being updated to 13 playerEventCB: container [Q:0] has being updated to 14 playerEventCB: container [Q:0] has being updated to 16 loadContent: 0x55e307bdc290 (Q:0) qml: Set queue position view at -1 qml: Set queue position view at 0 loadContent: 0x55e307bdc290 (Q:0) playerEventCB: container [Q:0] has being updated to 19 loadContent: 0x55e308fc4860 () (SONOS)WSResponse: server error (500) qml: Fault: tokenRefreshRequired

R8s6 commented 1 year ago

Just to confirm that I'm having the same problem, too, built from source (Arch AUR). It started about this week (Dec 20, 2022).

janbar commented 1 year ago

I think you need to re-handshake your connection to Spotify. To do that: delete your service Spotify previously configured, and add it again. There the app will start a new handshake.

scottwallacesh commented 1 year ago

Correct, but then after an hour you see the tokenRefreshRequired message again.

R8s6 commented 1 year ago

I also confirm that removing Spotify and then re-adding it works only temporarily, and in my case, stopped working the next day (and because I haven't been listening for more than an hour after it was re-added, it might have stopped just an hour later as @scottwallacesh reported).

stmasch commented 1 year ago

I have the same problem since the last update of Noson. Before it worked. What janbar wrote above didn't help anyway. I think he must research his last update for solving the issue.

I deleted Noson and installed Unofficial Sonos Controller even it has some features less than Noson. But Spotify, TunIn aso. work perfect. You can also combine both depending on what you wanna do. But then you have to open either Noson or Unofficial Sonos Controller.

DasJott commented 1 year ago

I could imagine that Noson has no refresh token functionality implemented and Spotify simply shortened the livespan of the access token to an hour. So Noson would have to refetch an access token, using the refresh token.

The "unofficial Sonos Controller" doesn't do anything except for eternally showing that it searches for the Sonos system. You can approach that with a png as well, no need for an executable application.

jvanveen commented 1 year ago

Same issue here, probably something that changed at the Spotify side? ncspot also seem to have some issues login in. (not sure if that's related)

janbar commented 1 year ago

Hi, nothing was changed in the code of noson since 4 months. Token refreshing has been implemented from long time, but seems Spotify api changed recently. Must be investigated ...

janbar commented 1 year ago

I need debug log to investigate this issue...

janbar commented 1 year ago

So, I get fixed this bug. The new release including the patch is 5.3.3.

The root cause is the new Spotify api uses an empty namespace, that wasn't expected, and in my opinion a bad practice. But it is like that today: you must plan for the worst !

scottwallacesh commented 1 year ago

I refreshed my Snap instance and it says, v5.4.0 -- and it appears to be working well!

jvanveen commented 1 year ago

Thanks for the fast fix! Recompiled 5.4.0 on my Pinephone pro, and it works like a charm! Glad I can play music again on my Sonos speakers using Noson-app :D

jasetthomas commented 1 year ago

Thanks for the update - I confirm it worked. I made a donation as thanks for the timely fix.