Skip to content

Commit 1f8dcfb

Browse files
committed
fixes
1 parent 7c8b32b commit 1f8dcfb

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

nowplaying/oauth2.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def get_redirect_uri(self, token_type: str = 'main') -> str: # pylint: disable=
403403
return f'http://localhost:{port}/{redirect_path}'
404404

405405
@staticmethod
406-
async def handle_oauth_redirect(request, oauth_config: dict):
406+
async def handle_oauth_redirect(request, oauth_config: dict, config, jinja2_env):
407407
"""Generic OAuth2 redirect handler for any service.
408408
409409
This method handles the OAuth2 authorization code flow redirect for any service.
@@ -420,12 +420,14 @@ async def handle_oauth_redirect(request, oauth_config: dict):
420420
- 'redirect_path': Path component for redirect URI (e.g., 'kickredirect')
421421
- 'token_keys': Dict with 'access' and 'refresh' keys for token storage
422422
- 'success_template': Success template name (optional)
423+
config: The config object (nowplaying.config.ConfigFile)
424+
jinja2_env: The Jinja2 environment (jinja2.Environment)
423425
424426
Returns:
425427
aiohttp.web.Response: HTML response for the OAuth flow result
426428
"""
427429
# Initialize helper
428-
helper = _OAuthRedirectHelper(request, oauth_config)
430+
helper = _OAuthRedirectHelper(request, oauth_config, config, jinja2_env)
429431

430432
# Process OAuth flow steps
431433
if error_response := helper.handle_oauth_error():
@@ -441,7 +443,7 @@ async def handle_oauth_redirect(request, oauth_config: dict):
441443
class _OAuthRedirectHelper: # pylint: disable=too-many-instance-attributes
442444
"""Helper class to handle OAuth redirect processing steps."""
443445

444-
def __init__(self, request: web.Request, oauth_config: dict):
446+
def __init__(self, request: web.Request, oauth_config: dict, config, jinja2_env):
445447
self.request = request
446448
self.oauth_config = oauth_config
447449
self.params = dict(request.query)
@@ -457,10 +459,9 @@ def __init__(self, request: web.Request, oauth_config: dict):
457459
self.success_template = oauth_config.get('success_template',
458460
f"{oauth_config['template_prefix']}_success.htm")
459461

460-
# Get app context - use string constants to avoid circular import
461-
self.config = request.app['config']
462+
# Use provided config and jinja2 environment
463+
self.config = config
462464
self.config.get()
463-
jinja2_env = request.app['jinja2']
464465
self.load_template = self._create_template_loader(jinja2_env)
465466

466467
# Log redirect for debugging (don't log auth code for security)

nowplaying/processes/webserver.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,11 @@ async def internals(request: web.Request):
475475
@staticmethod
476476
async def _handle_oauth_redirect(request: web.Request, oauth_config: dict) -> web.Response:
477477
"""Generic OAuth2 redirect handler - delegates to base OAuth2 class."""
478-
return await nowplaying.oauth2.OAuth2Client.handle_oauth_redirect(request, oauth_config)
478+
# Pass config and jinja2 environment from app context using correct keys
479+
config = request.app[CONFIG_KEY]
480+
jinja2_env = request.app[JINJA2_KEY]
481+
return await nowplaying.oauth2.OAuth2Client.handle_oauth_redirect(
482+
request, oauth_config, config, jinja2_env)
479483

480484

481485
async def kickredirect_handler(self, request: web.Request): # pylint: disable=no-self-use

0 commit comments

Comments
 (0)