skuethe / MMM-Spotify

Spotify display and controller for MagicMirror
MIT License
68 stars 17 forks source link

No browser access inside Magic Mirror2 to grant account permissions #169

Closed a-waider closed 3 years ago

a-waider commented 3 years ago

Hi there,

how do I connect my Spotify account without having connected any periphial (mouse, keyboard and screen) to my magic mirror? The problem is that I can't grant the access to my account because i can't interract with the browser opened by first-auth.js.

The log if it helps solving my issue.

[SPOTIFY - ****] Spotify version 2.0.3  Initialized...
[SPOTIFY - ****] AUTH: Opening the browser for authentication on Spotify...
[SPOTIFY - ****] AUTH: express app started and listening on port 8888
[SPOTIFY - ****] AUTH: Failed to automatically open the URL. Copy/paste this in your browser:
 https://accounts.spotify.com/authorize?response_type=code&client_id=*****&scope=user-read-private%20app-remote-control%20playlist-read-private%20streaming%20user-read-playback-state%20user-modify-playback-state&redirect_uri=http%3A%2F%2Flocalhost%3A8888%2Fcallback&state=1629555947767&show_dialog=true
[SPOTIFY - ****] Error in authentication:
Error: Exited with code 3
    at ChildProcess.<anonymous> (/opt/magic_mirror/modules/MMM-Spotify/node_modules/open/index.js:122:13)
    at Object.onceWrapper (events.js:421:26)
    at ChildProcess.emit (events.js:314:20)
    at maybeClose (internal/child_process.js:1022:16)
    at Socket.<anonymous> (internal/child_process.js:444:11)
    at Socket.emit (events.js:314:20)
    at Pipe.<anonymous> (net.js:675:12)
[SPOTIFY] Authorization process finished!

My Magic Mirror2 in running in server only mode inside a docker container. So no browser support in there.

skuethe commented 3 years ago

Hi there. Okay, that probably needs some enhancements to work. Could you share your docker setup (image used and startup options set [docker-compose file or whatever])? Then I could more easily get into debugging :)

I have given up on trying to use the Docker setup since long ago, because it caused a lot of unnecessary problems with MM²

a-waider commented 3 years ago

Okay, here is the magic mirror part of my docker-compose file:

    magic-mirror:
        image: bastilimbach/docker-magicmirror
        container_name: magic-mirror
        restart: unless-stopped
        ports: # Only temporary during authentication
            - 8888:8888
        expose:
            - 80
        volumes:
            - ./magic_mirror/config:/opt/magic_mirror/config
            - ./magic_mirror/css/custom.css:/opt/magic_mirror/css/custom.css
            - ./magic_mirror/modules:/opt/magic_mirror/modules
        environment:
            TZ: Europe/Berlin
        networks:
            - web_proxy

I kinda got it to work, but it definetly needs some tweaks. I temporarily forwarded the port 8888 to the container. Then I forwarded the Redirect from the Spotify auth endpoint to the IP of my server where my Docker containers are running.

Maybe introduce another config variable (In the Magic Mirror config.js) to set the local IP to where the server is accessible?

skuethe commented 3 years ago

Thank you for the config sharing.

Without looking any further into it I am currently thinking about optimizing the auth process a bit if there is no browser available. But this goes more into the direction of providing documentation for doing the auth process manually. Adding some kind of config variable is just more confusing than it will help I fear. And docker usage with MM² is still an edge case most of the times.

Nevertheless, I will try to setup a Pi with docker to use it for some testing on this matter.

a-waider commented 3 years ago

For testing purposes you can just install docker on your main machine. Magic Mirror inside Docker is afaik server only mode.

But in my opinion it is pretty common not having physical access to magic mirror with mouse and keyboard. So it would be nice to have the callback url pointed directly to magic mirror.

skuethe commented 3 years ago

So, I have done some major adjustments - also taking the time to upgrade / switch some outdated / discontinued npm packages. First testing is looking promising. Could you do me a favour and validate if these changes work for you?

Changes merged in current development branch: https://github.com/skuethe/MMM-Spotify/tree/development

I also added a lot of new documentation regarding the usage of custom callback URLs - specially for docker setups: https://github.com/skuethe/MMM-Spotify/tree/development#custom-callback

In short: the first_auth.js process is now not failing if you have a custom callback URL configured inside your spotify.config.json. It will print out the auth URL and wait 5mins for you to perform authentication and authorization to Spotify.

a-waider commented 3 years ago

Yeah, seems good :)

skuethe commented 3 years ago

Great, thanks. I will do some more testing on my side - especially with multi user setup and will then schedule the next release.