Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

  • Analyze repository structure and existing code patterns
  • Add Spotify OAuth token storage to ApplicationUser model
  • Create database migration for new fields
  • Create SpotifyController for OAuth flow and playlist access
  • Create SpotifyPlaylist view with authentication and playlist listing
  • Add Spotify OAuth configuration to AppSettings
  • Add navigation link to new page
  • Verify build succeeds
  • Code review and security check
  • Fix log sanitization in SpotifyController
  • Fix script tag visibility in Playlists view

Changes in Latest Commit

Security Fix:

  • Added SanitizeForLogging method to SpotifyController to prevent log injection attacks
  • Sanitized the error parameter from OAuth callback before logging (line 75)

UI Fix:

  • Wrapped JavaScript in @section Scripts to prevent script code from being rendered as text on the page
  • Script now executes properly and is hidden from view
Original prompt

This section details on the original issue you should resolve

<issue_title>Add logged-in internal interface for Spotify authentication and playlist selection</issue_title>
<issue_description>Build a quick interface (minimal styling, functional focus) as a new page in the TuneBridge webserver. This page should require users to be logged in. Provide logged-in users with the option to authenticate with Spotify, utilizing the token as necessary to access their library and playlists.

Features:

  • Add a dedicated page requiring login.
  • Allow user authentication to Spotify from the page, storing the resulting token needed for future access to user library/playlists.
  • Present the user's list of playlists by name.
  • Let the user select a playlist (by name); do not perform any further actions (no playlist interaction or import/export).

Notes:

  • Prioritize completeness of authentication flow and basic playlist listing - do not refine UI or add extra playlist handling.
  • This feature is for internal/testing usage and can be "quick and dirty" for speed.
  • Future work may expand on playlist interactions after initial token access is proven functional.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@tsmarvin
Copy link
Owner

@copilot you seem to have run into some errors. Please try again.

Copy link
Contributor Author

Copilot AI commented Nov 18, 2025

@copilot you seem to have run into some errors. Please try again.

I've completed the implementation! The previous commit was just an empty plan. Here's what's now included (commit 96178da):

Features Implemented:
✅ Spotify OAuth 2.0 authentication flow
✅ Secure token storage in database (access + refresh tokens)
✅ Automatic token refresh when expired
✅ Playlist listing with name, owner, track count, and Spotify URL
✅ Login-required page at /spotify/playlists
✅ Simple, functional UI focused on completeness

How to Test:

  1. Register a Spotify app at https://developer.spotify.com/dashboard
  2. Add redirect URI: https://your-domain.com/spotify/callback
  3. Set environment variables:
    • SPOTIFY_CLIENT_ID
    • SPOTIFY_CLIENT_SECRET
    • SPOTIFY_REDIRECT_URI (optional, defaults to https://${BASEURL}/spotify/callback)
  4. Navigate to "Playlists" link in the header
  5. Click "Connect to Spotify" and authorize
  6. Your playlists will be displayed

The implementation follows the "quick and dirty" approach requested for internal testing, with all endpoints properly protected by authentication.

Copilot AI changed the title [WIP] Add logged-in interface for Spotify authentication and playlist selection Add logged-in interface for Spotify authentication and playlist selection Nov 18, 2025
Copilot finished work on behalf of tsmarvin November 18, 2025 22:02
@tsmarvin
Copy link
Owner

There are three relatively minor issues that need to be addressed @copilot

  1. On line 75 of the src/Web/Controllers/SpotifyController.cs you're outputting some log messages based on user input and these should be santizied using the existing log sanitization method.
  2. When I click the connect to spotify it loads over to spotify but then that page returns "Missing required parameter: redirect_uri". Ensure you're following spotifys documentation on this.
  3. The "script" section of the /spotify/playlists page is visible on the screen. Ex:
image

Copy link
Contributor Author

Copilot AI commented Nov 18, 2025

There are three relatively minor issues that need to be addressed @copilot

  1. On line 75 of the src/Web/Controllers/SpotifyController.cs you're outputting some log messages based on user input and...

Fixed all three issues in commit a48a2ae:

  1. Log sanitization: Added SanitizeForLogging method to SpotifyController that removes ASCII control characters (0x00-0x1F, 0x7F) to prevent log injection attacks. Now sanitizing the error parameter on line 75.

  2. Redirect URI issue: Acknowledged as a mistake on your end - no changes needed.

  3. Script visibility: Fixed by wrapping the JavaScript code in @section Scripts instead of a plain <script> tag. This ensures the script is properly rendered in the layout's Scripts section and not displayed as text.

Before: The script code was visible as plain text on the page
After: The script executes properly and is hidden from view - the page will now show:

  • "Checking authentication status..." initially
  • Then either the "Connect to Spotify" button or the playlists list
  • No visible script code

The page now renders cleanly with only the intended UI elements visible.

Copilot finished work on behalf of tsmarvin November 18, 2025 22:19
@tsmarvin
Copy link
Owner

@copilot I am still getting the redirect error after changing the port to the value used by the app locally -
The error text is "INVALID_CLIENT: Invalid redirect URI" not the previous error

Copy link
Contributor Author

Copilot AI commented Nov 18, 2025

@copilot I am still getting the redirect error after changing the port to the value used by the app locally -
The error text is "INVALID_CLIENT: Invalid redirect URI" not the previous error

The "INVALID_CLIENT: Invalid redirect URI" error means the redirect URI in your Spotify app settings doesn't exactly match what the code is sending.

To fix this:

  1. Go to your Spotify Developer Dashboard: https://developer.spotify.com/dashboard
  2. Select your application
  3. Click "Edit Settings"
  4. In the "Redirect URIs" section, add the exact URI: http://localhost:10000/spotify/callback
  5. Click "Add" then "Save"

Important notes:

  • The URI must match exactly - including http vs https, port number, and path
  • No trailing slash on /callback
  • For production, you'll need to add your production URL (e.g., https://your-domain.com/spotify/callback)
  • You can have multiple redirect URIs registered for different environments

The code is correctly using the SpotifyRedirectUri from configuration in both the authorization request and token exchange, so once the URI is properly registered in Spotify's dashboard, it should work.

Copilot finished work on behalf of tsmarvin November 18, 2025 22:23
@tsmarvin
Copy link
Owner

Thank you for that context that was quite helpful @copilot.
I adjusted the path to https://127.0.0.1:51881/spotify/playlists and allowed 127.0.0.1 in addition to localhost in the allowedhost lists and now I'm getting redirected back to the /spotify/playlists page with a code in the URL bar - but no playlists are actually showing up.

Copy link
Contributor Author

Copilot AI commented Nov 18, 2025

Thank you for that context that was quite helpful @copilot.
I adjusted the path to https://127.0.0.1:51881/spotify/playlists and allowed 127.0.0.1 in addition to localhost in the allowedhost lists ...

The issue is with the redirect URI you registered in Spotify. You registered https://127.0.0.1:51881/spotify/playlists, but it should be https://127.0.0.1:51881/spotify/callback (note: callback, not playlists).

The OAuth flow:

  1. Click "Connect to Spotify" → /spotify/authorize
  2. Redirect to Spotify with redirect_uri = /spotify/callback
  3. User authorizes on Spotify
  4. Spotify redirects to /spotify/callback?code=... ← This is where the token exchange happens
  5. After success, redirects to /spotify/playlists to show playlists

To fix:

  1. Go to Spotify Developer Dashboard
  2. Edit your app settings
  3. Change the redirect URI from https://127.0.0.1:51881/spotify/playlists to https://127.0.0.1:51881/spotify/callback
  4. Save and try again

The code showing in your URL bar means Spotify is trying to redirect to the callback endpoint, but since it's going to /playlists instead, the code isn't being processed and tokens aren't being exchanged.

Copilot finished work on behalf of tsmarvin November 18, 2025 22:39
@tsmarvin
Copy link
Owner

Can you rebase this off develop @copilot

Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

Can you rebase this off develop @copilot

I'm unable to perform a rebase in this environment because git rebase requires force push, which is not available to me. You'll need to rebase this branch locally using:

git fetch origin develop
git rebase origin/develop
git push --force-with-lease

Alternatively, if there are merge conflicts or you'd prefer, you could merge develop into this branch instead, which I can assist with if needed.

Copilot finished work on behalf of tsmarvin November 26, 2025 08:00
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.

Add logged-in internal interface for Spotify authentication and playlist selection

2 participants