|
17 | 17 | from airweave.core.logging import ContextualLogger, LoggerConfigurator, logger |
18 | 18 | from airweave.core.sync_cursor_service import sync_cursor_service |
19 | 19 | from airweave.platform.auth_providers._base import BaseAuthProvider |
20 | | -from airweave.platform.auth_providers.auth_result import AuthProviderMode |
21 | 20 | from airweave.platform.destinations._base import BaseDestination |
22 | 21 | from airweave.platform.entities._base import BaseEntity |
23 | 22 | from airweave.platform.locator import resource_locator |
@@ -473,34 +472,26 @@ async def _setup_token_manager( |
473 | 472 | ) -> None: |
474 | 473 | """Set up token manager for OAuth sources.""" |
475 | 474 | short_name = source_connection_data["short_name"] |
476 | | - auth_config_class_name = source_connection_data.get("auth_config_class") |
477 | 475 | source_model = source_connection_data.get("source_model") |
478 | 476 |
|
479 | | - # Determine if we should create a token manager |
| 477 | + # Determine if we should create a token manager based on oauth_type |
480 | 478 | should_create_token_manager = False |
481 | 479 |
|
482 | | - # Case 1: Sources with OAuth2AuthConfig or its subclasses |
483 | | - if auth_config_class_name: |
484 | | - try: |
485 | | - # Get the auth config class |
486 | | - auth_config_class = resource_locator.get_auth_config(auth_config_class_name) |
487 | | - |
488 | | - # Check if it's a subclass of OAuth2AuthConfig |
489 | | - from airweave.platform.configs.auth import OAuth2AuthConfig |
490 | | - |
491 | | - if issubclass(auth_config_class, OAuth2AuthConfig): |
492 | | - should_create_token_manager = True |
493 | | - except Exception as e: |
494 | | - logger.warning(f"Could not check auth config class for {short_name}: {str(e)}") |
| 480 | + if source_model and hasattr(source_model, "oauth_type") and source_model.oauth_type: |
| 481 | + # Import OAuthType enum |
| 482 | + from airweave.schemas.source_connection import OAuthType |
495 | 483 |
|
496 | | - # Case 2: OAuth sources without auth_config_class (e.g., Asana, Google Calendar) |
497 | | - # These sources still need token management for refresh |
498 | | - elif source_model and hasattr(source_model, "oauth_type") and source_model.oauth_type: |
499 | | - # Check if we have OAuth credentials (dict with access_token) |
500 | | - if isinstance(source_credentials, dict) and "access_token" in source_credentials: |
| 484 | + # Only create token manager for sources that support token refresh |
| 485 | + if source_model.oauth_type in (OAuthType.WITH_REFRESH, OAuthType.WITH_ROTATING_REFRESH): |
501 | 486 | should_create_token_manager = True |
502 | 487 | logger.debug( |
503 | | - f"✅ OAuth source {short_name} without auth_config_class will use token manager" |
| 488 | + f"✅ OAuth source {short_name} with oauth_type={source_model.oauth_type.value} " |
| 489 | + f"will use token manager for refresh" |
| 490 | + ) |
| 491 | + else: |
| 492 | + logger.debug( |
| 493 | + f"⏭️ Skipping token manager for {short_name} - " |
| 494 | + f"oauth_type={source_model.oauth_type} does not support token refresh" |
504 | 495 | ) |
505 | 496 |
|
506 | 497 | if should_create_token_manager: |
|
0 commit comments