Skip to content

Add access_token option - #370

Merged
frenck merged 1 commit into
hassio-addons:mainfrom
marmarek:oauth
Aug 19, 2026
Merged

Add access_token option#370
frenck merged 1 commit into
hassio-addons:mainfrom
marmarek:oauth

Conversation

@marmarek

@marmarek marmarek commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

This allows logging into specific spotify account. Since the token needs to be set on the cmdline only once (to generate credentials.json), switching to another account is a bit awkward - it requires removing old credentials.json (by setting token to empty) and only then setting new one.
With this, I can successfully use Spotify Premium account again.

Related Issues

Fixes #369

Summary by CodeRabbit

  • New Features

    • Added access token configuration option for direct Spotify account authentication
    • Implemented credential caching to streamline authentication after initial setup
    • Added token refresh capability via configuration reset and app restart
  • Documentation

    • Updated documentation with configuration and update instructions for the access token

This allows logging into specific spotify account.

The token is short-lived and providing expired token makes the app fail
to start. But once credentials.json is cached, librespot remains logged
in even the token is not set on the command line anymore.

Fixes hassio-addons#369
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The Spotify Connect add-on gains an access_token configuration option. The field is added to config.yaml with an empty default and a str schema entry. The librespot run script gains logic to create a persistent system-cache directory, conditionally pass --access-token to librespot when no cached credentials exist, and delete credentials.json when the token is cleared. Usage is documented in DOCS.md.

Changes

access_token authentication support

Layer / File(s) Summary
Config schema and librespot run script wiring
spotify/config.yaml, spotify/rootfs/etc/services.d/librespot/run
Adds access_token: "" default and access_token: str schema entry; extends the run script to create /data/system-cache, pass --system-cache to librespot, inject --access-token when no cached credentials.json exists, and delete credentials.json when the configured token is empty.
Documentation for access_token option
spotify/DOCS.md
Adds an "Option: access_token" subsection describing token-based login, a link to the librespot options reference, and the required update procedure (clear token → restart → set new token).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • hassio-addons/app-spotify-connect#364: Removes the old username/password options and their --username/--password CLI wiring from the librespot run script, config, and docs — the direct predecessor to this PR's new access_token-based authentication approach.

Poem

🐇 Hoppin' through the music stream,
A token tucked beneath my paw —
No passwords lost, no broken dream,
Just cache it clean without a flaw.
One restart hops, the rhythm flows,
Bound to your account — off it goes! 🎵

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add access_token option' directly and clearly describes the main change in the pull request.
Linked Issues check ✅ Passed The PR implementation meets all coding requirements from issue #369: it adds --system-cache support via config option, implements --access-token configuration, and enables persistent Spotify account binding.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #369 requirements: documentation updates, configuration schema additions, and authentication script modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@spotify/rootfs/etc/services.d/librespot/run`:
- Around line 41-43: The conditional block checking
`/data/system-cache/credentials.json` and using `bashio::config.is_empty
'access_token'` is too broad because `access_token` defaults to empty, causing
cached credentials to be deleted on every restart. Modify the condition to only
delete the credentials cache when the user has explicitly provided a new
access_token value (i.e., when access_token is NOT empty), rather than when it
is empty. This will preserve cached login credentials across restarts while
still allowing the cache to be cleared when a user intentionally provides a new
token.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c2693cf5-308b-4912-b525-dafe43eeb10f

📥 Commits

Reviewing files that changed from the base of the PR and between d4f20aa and 49fd9d6.

📒 Files selected for processing (3)
  • spotify/DOCS.md
  • spotify/config.yaml
  • spotify/rootfs/etc/services.d/librespot/run

Comment thread spotify/rootfs/etc/services.d/librespot/run

@frenck frenck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @marmarek 👍

../Frenck

                       

Blogging my personal ramblings at frenck.dev

@frenck
frenck merged commit db0f70c into hassio-addons:main Aug 19, 2026
@frenck frenck added the new-feature New features or options. label Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New features or options.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add options to bind to specific spotify account

2 participants