Skip to content

Commit

Permalink
fix: twiiter binding
Browse files Browse the repository at this point in the history
  • Loading branch information
hyacinthus committed Feb 2, 2025
1 parent e2f222f commit b887065
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 0 additions & 7 deletions app/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from app.core.graph import create_agent
from app.core.skill import SkillStore
from app.services.twitter.client import TwitterClient
from app.services.twitter.oauth2 import get_authorization_url
from models.agent import Agent, AgentData
from models.db import get_coon, get_session
from models.skill import AgentSkillData, ThreadSkillData
Expand Down Expand Up @@ -227,12 +226,6 @@ def initialize_agent(aid):
)
else:
logger.info(f"Twitter client needs authentication for agent {aid}")
twitter_prompt = (
"\n\nWhen you need to use any twitter tool, "
f"tell the person helping you to authenticate the Twitter account using this link: {get_authorization_url(aid)} \n"
"Remember, the link will be expired. So you can only use this one, not use other links in the conversation history.\n"
"Display links on separate lines, with a blank line before and after, not use markdown.\n\n"
)
except Exception as e:
logger.warning(f"Failed to initialize Twitter client for agent {aid}: {e}")

Expand Down
12 changes: 10 additions & 2 deletions app/services/twitter/oauth2.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""Twitter OAuth2 authentication module."""

from fastapi import APIRouter
from fastapi import APIRouter, Depends
from pydantic import BaseModel
from requests.auth import HTTPBasicAuth
from requests_oauthlib import OAuth2Session

from app.config.config import config
from utils.middleware import create_jwt_middleware

# Create JWT middleware with admin config
verify_jwt = create_jwt_middleware(config.admin_auth_enabled, config.admin_jwt_secret)


# this class is forked from:
Expand Down Expand Up @@ -84,7 +88,11 @@ class TwitterAuthResponse(BaseModel):
router = APIRouter(tags=["Auth"])


@router.get("/auth/twitter", response_model=TwitterAuthResponse)
@router.get(
"/auth/twitter",
response_model=TwitterAuthResponse,
dependencies=[Depends(verify_jwt)],
)
async def get_twitter_auth_url(agent_id: str) -> TwitterAuthResponse:
"""Get Twitter OAuth2 authorization URL.
Expand Down

0 comments on commit b887065

Please sign in to comment.