Skip to content

Commit c092d5f

Browse files
authored
#96 Support OAUTH authentication (#97)
1 parent 4ec08f9 commit c092d5f

3 files changed

Lines changed: 34 additions & 47 deletions

File tree

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ ENV LOG_COMMAND_LINE=""
100100
ENV ONEVENT_COMMAND=""
101101
ENV ONEVENT_POST_ENDPOINT=""
102102

103+
ENV ENABLE_OAUTH=""
104+
103105
VOLUME /data/cache
104106
VOLUME /data/system-cache
105107
VOLUME /user/config

README.md

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ The following tables reports all the currently supported environment variables.
6565

6666
VARIABLE|DEFAULT|NOTES
6767
:---|:---|:---
68-
SPOTIFY_USERNAME||Your Spotify username. Required only if you want to disable discovery.
69-
SPOTIFY_PASSWORD||Your Spotify password. Required only if you want to disable discovery.
68+
SPOTIFY_USERNAME||Your Spotify username. Required only if you want to disable discovery (DEPRECATED).
69+
SPOTIFY_PASSWORD||Your Spotify password. Required only if you want to disable discovery (DEPRECATED).
7070
BITRATE|160|Bitrate (kbps): `96`, `160`, `320`. Defaults to `160`.
7171
BACKEND|alsa|Audio backend to use. Use `?` to list options. Currently possible values are `alsa` and `pulseaudio`.
7272
INITIAL_VOLUME||Initial volume in % from 0-100. Default for softvol: `50`. For the `alsa` mixer: the current volume.
@@ -109,6 +109,7 @@ AUDIO_GID||Specifies the gid for the group `audio`, it is required if you want t
109109
PARAMETER_PRIORITY||Where to look for a parameter first: `env` or `file`. For example, the `credentials.txt` file compared to `SPOTIFY_USERNAME` and `SPOTIFY_PASSWORD` environment variables. Defaults to `file`, meaning that each file is considered if it exists and if it contains the required values.
110110
ONEVENT_COMMAND||Specifies the name of a user defined script/executable that will be executed whenever a player event occurs. User defined scripts must be mounted to the `/userscripts/` folder and be made executable via `chmod u+x`. Internally maps to the `--onevent` flag of `librespot`. More info about usage can be found in [librespot's player event handler](https://github.com/librespot-org/librespot/blob/dev/src/player_event_handler.rs).
111111
ONEVENT_POST_ENDPOINT||Send a `POST` request with event data to the specified endpoint URL whenever a player event occurs. Request body is `json` encoded and contains all available fields specified by the [librespot's player event handler](https://github.com/librespot-org/librespot/blob/dev/src/player_event_handler.rs). Will be ignored if `ONEVENT_COMMAND` is set.
112+
ENABLE_OAUTH||Set to `headless` to enable OAUTH authentication. You will need to run the container interactively the first time. Recommended to enable when caching is also enabled.
112113
LOG_COMMAND_LINE||Set to `Y` or `y` to enable, `N` or `n` to disable. Defaults to `Y`.
113114

114115
### Volumes
@@ -134,6 +135,8 @@ SPOTIFY_USERNAME=myusername
134135
SPOTIFY_PASSWORD=mypassword
135136
```
136137

138+
Please note that username and password is deprecated as an authentication method in librespot.
139+
137140
##### Docker-compose in Alsa mode
138141

139142
With credentials:
@@ -143,9 +146,8 @@ With credentials:
143146
version: "3"
144147
145148
services:
146-
librespot-u12:
149+
librespot:
147150
image: giof71/librespot:latest
148-
container_name: librespot-u12
149151
devices:
150152
- /dev/snd:/dev/snd
151153
environment:
@@ -165,9 +167,8 @@ Discovery mode:
165167
version: "3"
166168
167169
services:
168-
librespot-u12:
170+
librespot:
169171
image: giof71/librespot:latest
170-
container_name: librespot-u12
171172
network_mode: host
172173
devices:
173174
- /dev/snd:/dev/snd
@@ -188,9 +189,8 @@ With credentials:
188189
version: "3"
189190
190191
services:
191-
librespot-pulse:
192+
librespot:
192193
image: giof71/librespot:latest
193-
container_name: librespot-pulse
194194
environment:
195195
- SPOTIFY_USERNAME=${SPOTIFY_USERNAME}
196196
- SPOTIFY_PASSWORD=${SPOTIFY_PASSWORD}
@@ -209,9 +209,8 @@ Discovery mode:
209209
version: "3"
210210
211211
services:
212-
librespot-pulse:
212+
librespot:
213213
image: giof71/librespot:latest
214-
container_name: librespot-pulse
215214
network_mode: host
216215
environment:
217216
- BACKEND=pulseaudio
@@ -226,25 +225,7 @@ services:
226225

227226
##### Docker run in Alsa mode
228227

229-
With credentials:
230-
231-
```text
232-
docker run -d --name librespot \
233-
--device /dev/snd \
234-
-e DEVICE_NAME=kodi-living-pi4-tuner \
235-
-e INITIAL_VOLUME=100 \
236-
-e BACKEND=alsa \
237-
-e DEVICE=hw:D10,0 \
238-
-e FORMAT=S32 \
239-
-e BITRATE=320 \
240-
-e INITIAL_VOLUME=100 \
241-
-e SPOTIFY_USERNAME=myusername \
242-
-e SPOTIFY_PASSWORD=mypassword \
243-
--restart unless-stopped \
244-
giof71/librespot:latest
245-
```
246-
247-
Discovery mode:
228+
In discovery mode:
248229

249230
```text
250231
docker run -d --name librespot \
@@ -269,22 +250,6 @@ Please note that with this DAC I had to specify S32 as the format. It would not
269250

270251
##### Docker run in PulseAudio mode
271252

272-
With credentials:
273-
274-
```text
275-
docker run -d
276-
-e PUID=1000 \
277-
-e PGID=1000 \
278-
-e BACKEND=pulseaudio \
279-
-e BITRATE=320 \
280-
-e SPOTIFY_USERNAME=myusername \
281-
-e SPOTIFY_PASSWORD=mypassword \
282-
-e DEVICE_NAME=librespot-pulse \
283-
-v /run/user/1000/pulse:/run/user/1000/pulse \
284-
--name librespot-pulse \
285-
giof71/librespot:latest
286-
```
287-
288253
Discovery mode:
289254

290255
```text
@@ -318,7 +283,20 @@ You can completely uninstall the service by running:
318283

319284
Of course, you might simply want run the Spotify binary client or the web player instead of this service, but this alternative will allow you to control the player on your desktop system from e.g. a smartphone or any Spotify client. And it will consume significantly less resources.
320285

321-
### Credentials file
286+
### Running interactively
287+
288+
If you have set ENABLE_OAUTH to `headless`, you will need to run your docker-compose.yaml interactively the first time.
289+
In order to do that, run your compose file using the following:
290+
291+
```text
292+
docker-compose run librespot
293+
```
294+
295+
assuming that `librespot` is the name of the service. Tune the command if needed.
296+
This command will let you see the container logs. You will have to open your browser at the displayed link, authenticated with Spotify and authorize the device, then paste the redirect URL to the terminal.
297+
After the first start, you can start the container as usual using `docker-compose up -d`.
298+
299+
### Credentials file (DEPRECATED)
322300

323301
Credentials can be stored on a separate file and mounted as `/user/config/credentials.txt`. The format is the same as the standard `.env` file.
324302
By defaults, `SPOTIFY_USERNAME` and `SPOTIFY_PASSWORD` entries found in this file have the priority against the correspondent environment variables, unless you set the variable `PARAMETER_PRIORITY` to `env`.
@@ -328,7 +306,7 @@ By defaults, `SPOTIFY_USERNAME` and `SPOTIFY_PASSWORD` entries found in this fil
328306
### Discovery
329307

330308
For discovery mode to work, you will need to specify `network_mode=host` on the compose file. Otherwise the player will not be discovered.
331-
In this mode, you will not need to provide username and password, but OTOH any premium spotify user on your network will be able to use your Librespot Player.
309+
In this mode, you will not need to provide username and password, but OTOH any premium spotify user on your network will be able to use your Librespot Player.
332310
Please note that even in "discovery" mode, the premium account is always required for playback, but it would only not be required to provide the credentials to the container.
333311

334312
### Dependency on Raspotify
@@ -350,6 +328,7 @@ Just be careful to use the tag you have built.
350328

351329
Change Date|Major Changes
352330
---|---
331+
2024-11-22|Add support for OAUTH authentication (see [#96](https://github.com/GioF71/librespot-docker/issues/96))
353332
2024-11-17|Fix docker warning (see [#94](https://github.com/GioF71/librespot-docker/issues/94))
354333
2024-11-16|Add support for `-onevent` (see [#91](https://github.com/GioF71/librespot-docker/issues/91)), thanks to [@QuadratClown](https://github.com/QuadratClown)
355334
2024-09-21|Use exec instead of eval

app/bin/run-librespot.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ elif [[ -n "$ONEVENT_POST_ENDPOINT" ]]; then
295295
CMD_LINE="$CMD_LINE --onevent '/app/bin/post-event-data.sh --url=$ONEVENT_POST_ENDPOINT'"
296296
fi
297297

298+
if [[ -n "${ENABLE_OAUTH}" ]]; then
299+
if [[ "${ENABLE_OAUTH^^}" == "HEADLESS" ]]; then
300+
CMD_LINE="$CMD_LINE --enable-oauth --oauth-port 0"
301+
fi
302+
fi
303+
298304
if [[ -z "${LOG_COMMAND_LINE}" || "${LOG_COMMAND_LINE^^}" = "Y" ]]; then
299305
ur=$(printf '*%.0s' $(seq 1 ${#SPOTIFY_USERNAME}))
300306
pr=$(printf '*%.0s' $(seq 1 ${#SPOTIFY_PASSWORD}))

0 commit comments

Comments
 (0)