Yooooomi / your_spotify

Self hosted Spotify tracking dashboard
GNU General Public License v3.0
3.07k stars 124 forks source link

Cannot GET /oauth/spotify/callback/oauth/spotify during first loggin #130

Closed jomsc closed 2 years ago

jomsc commented 2 years ago

Hello ! I am trying to setup this app inside my docker-compose file, but when I go to the web interface, it says Could not retrieve all the registered accounts and when I click login, I am redirected to http://192.168.1.200:8085/oauth/spotify/callback/oauth/spotify and the page yields the following error : Cannot GET oauth/spotify/callback/oauth/spotify

Here is my compose file :

version: "3.0"
server:
   image: yooooomi/your_spotify_server
   restart: always
   ports:
     - "8085:8080"
   links:
     - mongo
   depends_on:
     - mongo
   environment:
     - API_ENDPOINT=http://192.168.1.200:8085/oauth/spotify/callback # This MUST be included as a valid URL in the spot>    
     - CLIENT_ENDPOINT=http://192.168.1.200:8086
     - SPOTIFY_PUBLIC=_PUBLIC_
     - SPOTIFY_SECRET=_SECRET_
     - CORS=all

 mongo:
   container_name: mongo
   image: mongo:4.4.8
   volumes:
     - ./your_spotify_db:/data/db

 web:
   image: yooooomi/your_spotify_client
   restart: always
   ports:
     - "8086:3000"
   environment:
     - API_ENDPOINT=http://192.168.1.200:8085/oauth/spotify/callback

Here is a screenshot of my redirected URLs in my Spotify app :

image

Could someone help me ?

CaptaiNiveau commented 2 years ago

Funnily enough, I just came here to report a very similar issue. I'll describe it here first, and create a new issue if it's not caused by the same bug.

I set everything up and I can log in myself, however when I'm not logged in I get: Could not retrieve all the registered accounts. Clicking log in with Spotify works, the app is fully functional and shows all the stats. However, friends are unable to register, they just get sent back to /login with the same Could not retrieve all the registered accounts. I've restarted the service, however that did not help.

In the debugger window is a 401 unauthorized response from the backend for /backend/accounts (I set the base path to /backend, everything else works). Looking into the logs of the server docker, the 401 response shows up there as well.

I tried to ease the CORS setting and set it to all, however that didn't help either.

I'm using Swag with NGINX as a reverse proxy between Cloudflare and my server.

Here is my compose file: (notice there aren't any port mappings, since I'm proxying directly to the container from the swag container, inside the docker network)

services:
  backend:
    container_name: yourspotify-backend
    image: yooooomi/your_spotify_server
    networks:
      swag:
    restart: always
    links:
      - mongo
    depends_on:
      - mongo
    environment:
      - API_ENDPOINT=https://my.domain/backend # This MUST be included as a valid URL in the spotify dashboard (see below)
      - CLIENT_ENDPOINT=https://my.domain
      - SPOTIFY_PUBLIC=7f9b3469fa874fc78488a630c750fb6b
      - SPOTIFY_SECRET=d817c35124ac45c4964120dc57136678
      - CORS=all # https://my.domain # commented out the domain here, but that didn't help
  mongo:
    container_name: yourspotify-mongo
    image: mongo:4.4.8
    networks:
      swag:
    volumes:
      - /mnt/user/appdata/yourspotify/mongo:/data/db

  web:
    container_name: yourspotify-frontend
    image: yooooomi/your_spotify_client
    networks:
      swag:
    restart: always
    environment:
      - API_ENDPOINT=https://my.domain/backend

networks:
  swag:
    external: true

This is the nginx configuration:

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name spotify.*;

    include /config/nginx/ssl.conf;

    location /backend {
        return 301 $scheme://$host/backend/;
    }

    location /backend/ {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app yourspotify-backend;
        set $upstream_port 8080;
        set $upstream_proto http;
        rewrite /backend(.*) $1 break;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }

    location / {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app yourspotify-frontend;
        set $upstream_port 3000;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }
}

As I said, it all works after logging in with my own account. It doesn't work for anybody else though.

jomsc commented 2 years ago

Funnily enough, I just came here to report a very similar issue. I'll describe it here first, and create a new issue if it's not caused by the same bug.

Be careful, you showed your secret key.

Yooooomi commented 2 years ago

Hello @phesox ! The problem is quite simple, the API_ENDPOINT variable only needs the endpoint, and not the suffix you set. Setting API_ENDPOINT=192.168.1.200:8085 in both client and server should work.

jomsc commented 2 years ago

Hello @phesox ! The problem is quite simple, the API_ENDPOINT variable only needs the endpoint, and not the suffix you set. Setting API_ENDPOINT=192.168.1.200:8085 in both client and server should work.

Oh, it was as simple as that. It works now, and thanks a lot, I should have read the other answers more closely.

Thanks a lot for taking your time to answer !

CaptaiNiveau commented 2 years ago

Thanks for the reminder, I changed the Spotify application.