remove mcp session id

This commit is contained in:
Taylor Wilsdon
2025-07-26 12:05:22 -04:00
parent 0aeed0cc16
commit f0976514e2
4 changed files with 13 additions and 44 deletions

View File

@@ -15,7 +15,7 @@ from google.auth.transport.requests import Request
from google.auth.exceptions import RefreshError
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from auth.scopes import OAUTH_STATE_TO_SESSION_ID_MAP, SCOPES
from auth.scopes import SCOPES
# Configure logging
logging.basicConfig(level=logging.INFO)
@@ -346,7 +346,6 @@ def create_oauth_flow(
async def start_auth_flow(
mcp_session_id: Optional[str],
user_google_email: Optional[str],
service_name: str, # e.g., "Google Calendar", "Gmail" for user messages
redirect_uri: str, # Added redirect_uri as a required parameter
@@ -355,7 +354,6 @@ async def start_auth_flow(
Initiates the Google OAuth flow and returns an actionable message for the user.
Args:
mcp_session_id: The active MCP session ID.
user_google_email: The user's specified Google email, if provided.
service_name: The name of the Google service requiring auth (for user messages).
redirect_uri: The URI Google will redirect to after authorization.
@@ -378,7 +376,7 @@ async def start_auth_flow(
)
logger.info(
f"[start_auth_flow] Initiating auth for {user_display_name} (session: {mcp_session_id}) with global SCOPES."
f"[start_auth_flow] Initiating auth for {user_display_name} with global SCOPES."
)
try:
@@ -391,11 +389,6 @@ async def start_auth_flow(
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
oauth_state = os.urandom(16).hex()
if mcp_session_id:
OAUTH_STATE_TO_SESSION_ID_MAP[oauth_state] = mcp_session_id
logger.info(
f"[start_auth_flow] Stored mcp_session_id '{mcp_session_id}' for oauth_state '{oauth_state}'."
)
flow = create_oauth_flow(
scopes=SCOPES, # Use global SCOPES
@@ -417,11 +410,7 @@ async def start_auth_flow(
"**LLM, after presenting the link, instruct the user as follows:**",
"1. Click the link and complete the authorization in their browser.",
]
session_info_for_llm = (
f" (this will link to your current session {mcp_session_id})"
if mcp_session_id
else ""
)
session_info_for_llm = ""
if not initial_email_provided:
message_lines.extend(
@@ -773,7 +762,6 @@ async def get_authenticated_google_service(
# Generate auth URL and raise exception with it
auth_response = await start_auth_flow(
mcp_session_id=None, # Session ID not available in service layer
user_google_email=user_google_email,
service_name=f"Google {service_name.title()}",
redirect_uri=redirect_uri,

View File

@@ -18,7 +18,7 @@ from typing import Optional
from urllib.parse import urlparse
from auth.google_auth import handle_auth_callback, check_client_secrets
from auth.scopes import OAUTH_STATE_TO_SESSION_ID_MAP, SCOPES
from auth.scopes import SCOPES
from auth.oauth_responses import create_error_response, create_success_response, create_server_error_response
logger = logging.getLogger(__name__)
@@ -68,11 +68,7 @@ class MinimalOAuthServer:
logger.info(f"OAuth callback: Received code (state: {state}). Attempting to exchange for tokens.")
mcp_session_id: Optional[str] = OAUTH_STATE_TO_SESSION_ID_MAP.pop(state, None)
if mcp_session_id:
logger.info(f"OAuth callback: Retrieved MCP session ID '{mcp_session_id}' for state '{state}'.")
else:
logger.warning(f"OAuth callback: No MCP session ID found for state '{state}'. Auth will not be tied to a specific session.")
# Session ID tracking removed - not needed
# Exchange code for credentials
redirect_uri = get_oauth_redirect_uri(port=self.port, base_uri=self.base_uri)
@@ -80,11 +76,10 @@ class MinimalOAuthServer:
scopes=SCOPES,
authorization_response=str(request.url),
redirect_uri=redirect_uri,
session_id=mcp_session_id
session_id=None
)
log_session_part = f" (linked to session: {mcp_session_id})" if mcp_session_id else ""
logger.info(f"OAuth callback: Successfully authenticated user: {verified_user_id} (state: {state}){log_session_part}.")
logger.info(f"OAuth callback: Successfully authenticated user: {verified_user_id} (state: {state}).")
# Return success page using shared template
return create_success_response(verified_user_id)

View File

@@ -5,14 +5,9 @@ This module centralizes OAuth scope definitions for Google Workspace integration
Separated from service_decorator.py to avoid circular imports.
"""
import logging
from typing import Dict
logger = logging.getLogger(__name__)
# Temporary map to associate OAuth state with MCP session ID
# This should ideally be a more robust cache in a production system (e.g., Redis)
OAUTH_STATE_TO_SESSION_ID_MAP: Dict[str, str] = {}
# Individual OAuth Scope Constants
USERINFO_EMAIL_SCOPE = 'https://www.googleapis.com/auth/userinfo.email'
OPENID_SCOPE = 'openid'