From 52a2cd1d03da2c2ec7c92ef9bb81b9ae696c0e03 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sun, 30 Nov 2025 14:15:21 +0100 Subject: [PATCH] Some fixes for the oauth redirect page --- .../controllers/webserver/controller.py | 25 ++-- .../helpers/resources/oauth_callback.html | 132 +++++++++++++----- 2 files changed, 103 insertions(+), 54 deletions(-) diff --git a/music_assistant/controllers/webserver/controller.py b/music_assistant/controllers/webserver/controller.py index ad62b83e..7d386cb7 100644 --- a/music_assistant/controllers/webserver/controller.py +++ b/music_assistant/controllers/webserver/controller.py @@ -820,7 +820,7 @@ class WebserverController(CoreController): self.logger.exception("Error during OAuth authorization") return web.json_response({"error": "Authorization failed"}, status=500) - async def _handle_auth_callback(self, request: web.Request) -> web.Response: + async def _handle_auth_callback(self, request: web.Request) -> web.Response: # noqa: PLR0915 """Handle OAuth callback.""" try: code = request.query.get("code") @@ -852,27 +852,20 @@ class WebserverController(CoreController): device_name = f"OAuth ({provider_id})" token = await self.auth.create_token(auth_result.user, device_name) - # Check if this is a remote client OAuth flow if auth_result.return_url and auth_result.return_url.startswith( "urn:ietf:wg:oauth:2.0:oob:auto:" ): - # Extract session ID from return URL session_id = auth_result.return_url.split(":")[-1] - # Store token in pending sessions if session_id in self.auth._pending_oauth_sessions: self.auth._pending_oauth_sessions[session_id] = token - # Show success page for remote auth - success_html = """ - - Authentication Successful - -

✓ Authentication Successful

-

You have successfully authenticated with Music Assistant.

-

You can now close this window and return to your application.

- - - """ + oauth_callback_html_path = str(RESOURCES_DIR.joinpath("oauth_callback.html")) + async with aiofiles.open(oauth_callback_html_path) as f: + success_html = await f.read() + + success_html = success_html.replace("{TOKEN}", token) + success_html = success_html.replace("{REDIRECT_URL}", "about:blank") + success_html = success_html.replace("{REQUIRES_CONSENT}", "false") + return web.Response(text=success_html, content_type="text/html") # Determine redirect URL (use return_url from OAuth flow or default to root) diff --git a/music_assistant/helpers/resources/oauth_callback.html b/music_assistant/helpers/resources/oauth_callback.html index 88933578..ef030e90 100644 --- a/music_assistant/helpers/resources/oauth_callback.html +++ b/music_assistant/helpers/resources/oauth_callback.html @@ -112,6 +112,33 @@ color: var(--text-secondary); font-size: 15px; } + + .close-button { + display: none; + margin-top: 24px; + padding: 12px 24px; + background: var(--primary); + color: white; + border: none; + border-radius: 10px; + font-size: 15px; + font-weight: 600; + cursor: pointer; + transition: all 0.2s ease; + } + + .close-button:hover { + filter: brightness(1.1); + transform: translateY(-1px); + } + + .close-button:active { + transform: translateY(0); + } + + .close-button.show { + display: inline-block; + } @@ -127,6 +154,7 @@

Login Successful!

Redirecting...

+
-- 2.34.1