successful client to server flow, not passing through. overcomplicated. need to refactor based on new fastmcp oauth wrapper
This commit is contained in:
@@ -295,6 +295,44 @@ class AuthCompatibilityLayer:
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to bridge legacy credentials to OAuth 2.1: {e}")
|
||||
|
||||
def get_credentials_from_oauth2_session(
|
||||
self,
|
||||
session_id: str,
|
||||
user_email: Optional[str] = None,
|
||||
) -> Optional[Credentials]:
|
||||
"""
|
||||
Get Google credentials from OAuth 2.1 session.
|
||||
|
||||
Args:
|
||||
session_id: OAuth 2.1 session ID
|
||||
user_email: Optional user email for validation
|
||||
|
||||
Returns:
|
||||
Google Credentials object or None
|
||||
"""
|
||||
if not self.oauth2_handler:
|
||||
return None
|
||||
|
||||
try:
|
||||
session = self.oauth2_handler.session_store.get_session(session_id)
|
||||
if not session:
|
||||
logger.debug(f"No OAuth 2.1 session found for {session_id}")
|
||||
return None
|
||||
|
||||
# Validate user if provided
|
||||
if user_email and session.user_id != user_email:
|
||||
logger.warning(
|
||||
f"Session user {session.user_id} doesn't match requested user {user_email}"
|
||||
)
|
||||
return None
|
||||
|
||||
# Convert to Google credentials
|
||||
return self._convert_oauth2_to_credentials(session.token_info)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get credentials from OAuth 2.1 session: {e}")
|
||||
return None
|
||||
|
||||
def create_enhanced_middleware(self):
|
||||
"""Create middleware that supports both OAuth 2.1 and legacy auth."""
|
||||
|
||||
@@ -186,6 +186,24 @@ class OAuth2Handler:
|
||||
|
||||
session = self.session_store.get_session(session_id)
|
||||
logger.info(f"Created session {session_id} for user {user_id}")
|
||||
|
||||
# Store in global OAuth 2.1 session store for Google services
|
||||
try:
|
||||
from auth.oauth21_session_store import get_oauth21_session_store
|
||||
store = get_oauth21_session_store()
|
||||
store.store_session(
|
||||
user_email=user_id,
|
||||
access_token=access_token,
|
||||
refresh_token=token_response.get("refresh_token"),
|
||||
token_uri=token_response.get("token_uri", "https://oauth2.googleapis.com/token"),
|
||||
client_id=self.config.client_id,
|
||||
client_secret=self.config.client_secret,
|
||||
scopes=token_info.get("scopes", []),
|
||||
expiry=token_info.get("expires_at"),
|
||||
session_id=session_id,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to store session in global store: {e}")
|
||||
|
||||
return session_id, session
|
||||
|
||||
|
||||
Reference in New Issue
Block a user