Viperinius / jellyfin-plugin-spotify-import

Import playlists from Spotify in Jellyfin
GNU General Public License v3.0
29 stars 2 forks source link

Authorize not doing anything #35

Closed mrepetto-certx closed 3 weeks ago

mrepetto-certx commented 3 weeks ago

Description I follow the instructions but when I click on authorize, nothing happens. The button seems to not respond, because I cannot see anything happening also in the Jellyfin logs.

Plugin settings Default options, I did not touch anything

Logs I do not have anything specific from jellyfin, my logs are:

[2024-08-24 06:23:18.298 +00:00] [ERR] [16] Namo.Plugin.InPlayerEpisodePreview.Api.InPlayerPreviewController: InPlayerEpisodePreviewPlugin: "Namo.Plugin.InPlayerEpisodePreview.Web.InPlayerPreview.js"
[2024-08-24 06:23:19.046 +00:00] [INF] [21] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.167.22.132" request
[2024-08-24 06:24:00.983 +00:00] [INF] [27] Emby.Server.Implementations.ApplicationHost: App needs to be restarted.
[2024-08-24 06:26:59.342 +00:00] [INF] [17] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.167.22.132" closed
[2024-08-24 06:27:46.148 +00:00] [ERR] [25] Namo.Plugin.InPlayerEpisodePreview.Api.InPlayerPreviewController: InPlayerEpisodePreviewPlugin: "Namo.Plugin.InPlayerEpisodePreview.Web.InPlayerPreview.js"
[2024-08-24 06:27:46.576 +00:00] [INF] [15] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.167.22.132" request
[2024-08-24 06:27:50.777 +00:00] [WRN] [25] Emby.Server.Implementations.HttpServer.WebSocketConnection: WS "192.167.22.132" error receiving data: "The remote party closed the WebSocket connection without completing the close handshake."
[2024-08-24 06:27:50.785 +00:00] [INF] [25] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.167.22.132" closed
[2024-08-24 06:31:07.182 +00:00] [INF] [27] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.167.22.132" request
mrepetto-certx commented 3 weeks ago

Looking at it with Firefox, I get the following error when clicking on authorize.

TypeError: config.headers is undefined
    fetch DataFetcher.ts:19
    __awaiter ClientScript:809
    __awaiter ClientScript:805
    fetch DataFetcher.ts:14
    default configurationpage:349
[configurationpage:362:21](http://192.168.1.183:8096/web/configurationpage?name=playlistconfigjs)
    default http://192.168.1.183:8096/web/configurationpage?name=playlistconfigjs:362
Viperinius commented 3 weeks ago

Which Jellyfin version are you on? I just tested 10.9.9 and plugin version 1.8.1.1 successfully using Firefox 129.0.2.

Do you see a POST request being sent in Firefox when you click on the button? Something like POST <url etc>/Viperinius.Plugin.SpotifyImport/SpotifyAuth

It is a bit odd because none of the things in the error message seem to come from the plugin (and I could not find them in the web client code of Jellyfin either). Could you tell me what lines you see in the Firefox debugger at the locations mentioned in the message? Especially

of configurationpage?name=playlistconfigjs

mrepetto-certx commented 3 weeks ago

Thank you for the quick reply. I'm running version 10.9.9 on a podman container, the plugin is version 1.8.1.1.

At line 349 I see:

        fetch(fullAuthUrl, { method: 'POST' }).then(function (res) {

Whereas in 362 I see:

            console.error(error);

I do not know if it is helpful but this happens to no matter which browser I tested and IOS and Windows app as well.

Viperinius commented 3 weeks ago

Hm, ok so the fetch errors out for some reason, odd. Let's try some things in the browser console, I don't really know why this might happen.

Does this generic fetch call print ok?

fetch('https://httpbin.org/post', { method: 'POST' }).then(console.log('ok')).catch((e) => console.err(e))

Then, try to generate the url used in the actual fetch call:

ApiClient.getUrl('Viperinius.Plugin.SpotifyImport' + '/SpotifyAuth', { 'baseUrl': ApiClient._serverAddress, 'api_key': ApiClient.accessToken() }) 

That one should print something like http://127.0.0.1:8096/Viperinius.Plugin.SpotifyImport/SpotifyAuth?baseUrl=http%3A%2F%2F127.0.0.1%3A8096&api_key=<...>

And next, let's try to replicate the failing fetch call (replace <...> with the api key you got from the generated url):

fetch('http://192.168.1.183:8096/Viperinius.Plugin.SpotifyImport/SpotifyAuth?api_key=<...>', { method: 'POST' }).then(console.log('ok')).catch((e) => console.err(e))

Lastly, does the button Clear Files at the bottom of the config page lead to the same errors or does that one work?

mrepetto-certx commented 3 weeks ago

From the first command I get the following: image

Second command gives me exactly what you said.

And third one: image

As for the Clear Files button, I do not see any. I only see Save. image

Viperinius commented 3 weeks ago

As for the Clear Files button, I do not see any. I only see Save.

Ah sorry, forgot that that button is only visible when there are any files to delete in the first place...

But back to the topic, do you use some special fork or old version of Firefox or addon that messes with its Javascript capabilities? It is very weird to see that console.err is not present and that fetch also seems not to work completely

Edit: just noticed that it should have been console.error and not err... So at least that one is ok. Could you try the third one again with that fixed

Viperinius commented 3 weeks ago

I have actually managed to get your result of the first test with Librewolf if the content security policy kicks in. But that should be displayed as a separate error between "ok" and the rejected promise.

mrepetto-certx commented 3 weeks ago

It is plain vanilla Firefox. I used it for debug because I am more familiar with it. But I’m experiencing the same behavior in chrome, edge and safari (on IOS). Let me know if you want logs from those browsers.

Viperinius commented 3 weeks ago

Could you maybe try the last one with either Firefox or another one again, using the fixed command?

fetch('http://192.168.1.183:8096/Viperinius.Plugin.SpotifyImport/SpotifyAuth?api_key=<...>', { method: 'POST' }).then(console.log('ok')).catch((e) => console.log(e))

I would expect that request to return with 400 Bad Request, If that does not work, I am a bit out of ideas. The only thing left to try would be trying to use the "builtin" fetch that jellyfin uses for their internal calls. But I have no idea, why a standard function like fetch should fail this bad.

Otherwise, you could check if the url from the above test returns the expected 400 status when done via command line or something like Postman, if you are familiar with that.

mrepetto-certx commented 3 weeks ago

Tried on Edge:

image

I know that I'm exposing the key, I'll change it later ;-)

Viperinius commented 3 weeks ago

Ok, last attempt, now using the custom fetch used in jellyfin-web itself:

ApiClient.fetch({ url: 'http://192.168.1.183:8096/Viperinius.Plugin.SpotifyImport/SpotifyAuth', type: 'POST', dataType: 'json', headers: { accept: 'application/json' }}, true).then(r => console.log(`:) ${JSON.stringify(r)}`)).catch(e => console.log(`:/ ${JSON.stringify(e)}`))

With that one, you dont need to supply any api key as long as you execute it in the tab with a logged in jellyfin session.

If that also errors out (other than 400 Bad Request), I am out of ideas as that exact method is used in a lot of other places in Jellyfin

mrepetto-certx commented 3 weeks ago

I tried and I got "400 (Bad Request)"

Viperinius commented 3 weeks ago

Alright great, then I will change the plugin to use that version

mrepetto-certx commented 3 weeks ago

Great! Thank you so much!

Viperinius commented 3 weeks ago

Release 1.9.0.0 contains the changes to the config page handling. As soon as your server updates the plugin, it should work now hopefully

mrepetto-certx commented 3 weeks ago

I confirm that everything works now; thank you so much!