adjust auth helper a small bit
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 14 Apr 2023 12:36:24 +0000 (14:36 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 14 Apr 2023 12:36:24 +0000 (14:36 +0200)
music_assistant/server/helpers/auth.py

index 46054370e1a7e017c728156c6bbef32c6fd7bad2..197b136bf48f202c408fbb948ecf0a015720c537 100644 (file)
@@ -45,8 +45,16 @@ class AuthenticationHelper:
 
     async def authenticate(self, auth_url: str, timeout: int = 60) -> dict[str, str]:
         """Start the auth process and return any query params if received on the callback."""
+        self.send_url(auth_url)
+        return await self.wait_for_callback(timeout)
+
+    def send_url(self, auth_url: str) -> None:
+        """Send the user to the given URL to authenticate (or fill in a code)."""
         # redirect the user in the frontend to the auth url
         self.mass.signal_event(EventType.AUTH_SESSION, self.session_id, auth_url)
+
+    async def wait_for_callback(self, timeout: int = 60) -> dict[str, str]:
+        """Wait for the external party to call the callback and return any query strings."""
         async with asyncio.timeout(timeout):
             return await self._callback_response.get()