Skip to content

Commit cd771fe

Browse files
authored
Merge pull request #1065 from airweave-ai/fix/token-manager-init
Fix: Create token manager based on oauth type not auth config class
2 parents a1d791d + 47be81d commit cd771fe

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

backend/airweave/platform/sync/factory.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from airweave.core.logging import ContextualLogger, LoggerConfigurator, logger
1818
from airweave.core.sync_cursor_service import sync_cursor_service
1919
from airweave.platform.auth_providers._base import BaseAuthProvider
20-
from airweave.platform.auth_providers.auth_result import AuthProviderMode
2120
from airweave.platform.destinations._base import BaseDestination
2221
from airweave.platform.entities._base import BaseEntity
2322
from airweave.platform.locator import resource_locator
@@ -473,34 +472,26 @@ async def _setup_token_manager(
473472
) -> None:
474473
"""Set up token manager for OAuth sources."""
475474
short_name = source_connection_data["short_name"]
476-
auth_config_class_name = source_connection_data.get("auth_config_class")
477475
source_model = source_connection_data.get("source_model")
478476

479-
# Determine if we should create a token manager
477+
# Determine if we should create a token manager based on oauth_type
480478
should_create_token_manager = False
481479

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
495483

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):
501486
should_create_token_manager = True
502487
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"
504495
)
505496

506497
if should_create_token_manager:

backend/airweave/search/factory.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -890,17 +890,29 @@ async def _instantiate_federated_source(
890890
ctx.logger.info(f"Proxy mode active for {source_connection.short_name}")
891891
source_instance.set_http_client_factory(auth_config["http_client_factory"])
892892

893-
# Step 8: Setup token manager for OAuth sources
894-
if source_model.oauth_type and isinstance(auth_config["credentials"], dict):
895-
self._setup_token_manager(
896-
source_instance,
897-
db,
898-
source_connection,
899-
source_connection_data.get("integration_credential_id"),
900-
auth_config["credentials"],
901-
ctx,
902-
auth_provider_instance=auth_config.get("auth_provider_instance"),
903-
)
893+
# Step 8: Setup token manager for OAuth sources that support refresh
894+
if source_model.oauth_type:
895+
from airweave.schemas.source_connection import OAuthType
896+
897+
# Only create token manager for sources with refresh capability
898+
if source_model.oauth_type in (
899+
OAuthType.WITH_REFRESH,
900+
OAuthType.WITH_ROTATING_REFRESH,
901+
):
902+
self._setup_token_manager(
903+
source_instance,
904+
db,
905+
source_connection,
906+
source_connection_data.get("integration_credential_id"),
907+
auth_config["credentials"],
908+
ctx,
909+
auth_provider_instance=auth_config.get("auth_provider_instance"),
910+
)
911+
else:
912+
ctx.logger.debug(
913+
f"⏭️ Skipping token manager for {source_connection.short_name} - "
914+
f"oauth_type={source_model.oauth_type} does not support token refresh"
915+
)
904916

905917
ctx.logger.info(
906918
f"Successfully instantiated federated source: {source_connection.short_name}"

0 commit comments

Comments
 (0)