Skip to content

feat: add runtime Spotify API credential configuration via web UI#557

Open
nebriv wants to merge 2 commits intosle118:master-v4.3from
nebriv:feature/spotify-nvs-credentials
Open

feat: add runtime Spotify API credential configuration via web UI#557
nebriv wants to merge 2 commits intosle118:master-v4.3from
nebriv:feature/spotify-nvs-credentials

Conversation

@nebriv
Copy link
Copy Markdown

@nebriv nebriv commented Mar 19, 2026

Created with Generative AI

I did most of the debugging with Claude, I tried to keep the modifications as tight as possible. But I'm VERY unfamiliar with js/ts, etc. Happy to address/answer any questions. I've flashed this two one Louder Esparagus devices and one Esparagus HiFi
https://sonocotta.com/louder-esparagus/
https://sonocotta.com/esparagus-hifi-medialink/

Ref #537

The baked-in Spotify client credentials have become invalid, causing HTTP 400 "invalid_client" errors from accounts.spotify.com/api/token and crashes/reboots when connecting via Spotify Connect.

Errors seen in debug/verbose logging on the console

[00:00:16.106] I AccessKeyFetcher.cpp:91: Token response (len=63): {"error":"invalid_client","error_description":"Invalid client"}
[00:00:16.118] E AccessKeyFetcher.cpp:137: Failed to fetch access token. Error: invalid_client, Description: Invalid client
[00:00:16.031] I HTTPClient.cpp:123: HTTP response parsed: HTTP/1.1 status=400, 14 headers

This was resulting in a kernel panic:

I2S abort!
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

This change allows Spotify client credentials (Client ID and Client Secret) to be configured at runtime through the web UI and stored in NVS, removing the need to rebuild firmware when credentials change or expire. Users can create their own Spotify Developer App at developer.spotify.com/dashboard and enter their credentials in the System tab.

Credentials are read from the existing cspot_config JSON in NVS at startup. If not set or empty, the compile-time defaults (CLIENT_ID / CLIENT_SECRET from client_info.h or environment) are used as a fallback, preserving existing behavior.

Backend (Shim.cpp):

  • Added clientId and clientSecret member variables to cspotPlayer
  • Constructor reads credentials from cspot_config JSON using the same cJSON_GetObjectItem pattern as deviceName, bitrate, and zeroConf
  • runTask() uses member variables instead of compile-time defines

Web UI (custom.js):

  • Added saveSpotifyConfig() function to persist credentials to NVS via /config.json POST, following the same pattern as saveAutoexec1()
  • Dynamically injects a "Spotify API Credentials" card in the System tab after the existing "Spotify (cSpot) Options" card
  • Card visibility is tied to the enable_cspot flag
  • Populates fields from stored cspot_config on page load, with timing coordination between getConfig() and getCommands() via window vars

Ref sle118#537

The baked-in Spotify client credentials have become invalid, causing
HTTP 400 "invalid_client" errors from accounts.spotify.com/api/token
and crashes/reboots when connecting via Spotify Connect.

This change allows Spotify client credentials (Client ID and Client
Secret) to be configured at runtime through the web UI and stored in
NVS, removing the need to rebuild firmware when credentials change or
expire. Users can create their own Spotify Developer App at
developer.spotify.com/dashboard and enter their credentials in the
System tab.

Credentials are read from the existing cspot_config JSON in NVS at
startup. If not set or empty, the compile-time defaults (CLIENT_ID /
CLIENT_SECRET from client_info.h or environment) are used as a
fallback, preserving existing behavior.

Backend (Shim.cpp):
- Added clientId and clientSecret member variables to cspotPlayer
- Constructor reads credentials from cspot_config JSON using the same
  cJSON_GetObjectItem pattern as deviceName, bitrate, and zeroConf
- runTask() uses member variables instead of compile-time defines

Web UI (custom.js):
- Added saveSpotifyConfig() function to persist credentials to NVS
  via /config.json POST, following the same pattern as saveAutoexec1()
- Dynamically injects a "Spotify API Credentials" card in the System
  tab after the existing "Spotify (cSpot) Options" card
- Card visibility is tied to the enable_cspot flag
- Populates fields from stored cspot_config on page load, with timing
  coordination between getConfig() and getCommands() via window vars
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the maintainability and user experience for Spotify Connect functionality by enabling dynamic configuration of API credentials via the web interface. Users can now manage their Spotify Client ID and Secret without requiring a firmware rebuild, addressing issues caused by expired or invalid hardcoded credentials. The changes span both the backend logic for reading and utilizing these credentials from non-volatile storage and the frontend for providing an intuitive configuration interface.

Highlights

  • Runtime Spotify API Credential Configuration: Introduced the ability to configure Spotify Client ID and Client Secret directly through the web UI, eliminating the need for firmware recompilation when credentials change or expire.
  • Non-Volatile Storage (NVS) Integration: Spotify credentials are now stored in NVS, with a fallback mechanism to use compile-time defaults if NVS entries are not found or are empty.
  • Backend Logic Update: Modified the cspotPlayer class in Shim.cpp to include clientId and clientSecret member variables, which are populated from NVS during initialization and used for Spotify authentication.
  • Web UI Enhancement: Added a new 'Spotify API Credentials' card to the System tab of the web UI, allowing users to input and save their custom Spotify Client ID and Secret.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully implements the runtime Spotify API credential configuration via the web UI, which is a valuable addition for users. The C++ backend correctly integrates the new clientId and clientSecret member variables, falling back to compile-time defines if not configured. The JavaScript frontend provides a clear user interface for entering and saving these credentials, along with appropriate feedback messages. The changes to the build-related files are consistent with the updated JavaScript bundles.

I've identified a few areas for improvement:

  • Robustness in C++ JSON parsing: A minor enhancement to safely handle potential NULL values from cJSON_GetObjectItem before calling strlen.
  • Frontend HTML structure: Consider separating the Spotify credentials card HTML structure from the JavaScript logic for better maintainability.
  • TypeScript declaration file: The auto-generated test.d.ts file contains redundant function declarations, which might indicate an issue with the build or type generation process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant