Skip to content

Commit cbaed00

Browse files
committed
Revert "Make it work"
This reverts commit 9fe578d.
1 parent 9fe578d commit cbaed00

4 files changed

Lines changed: 44 additions & 31 deletions

File tree

pydantic-ai/app_oauth.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import logging
22
import os
33

4+
from dotenv import load_dotenv
45
from slack_bolt import App
6+
from slack_bolt.oauth.oauth_settings import OAuthSettings
57
from slack_sdk import WebClient
68

79
from agent import get_model
810
from listeners import register_listeners
9-
from oauth import oauth_settings
11+
from oauth import BOT_SCOPES, USER_SCOPES, installation_store, state_store
1012

13+
load_dotenv(dotenv_path=".env", override=False)
1114
get_model() # Fail fast if no AI provider key is configured
1215

1316
logging.basicConfig(level=logging.DEBUG)
@@ -22,7 +25,14 @@
2225
# Allow bot-posted messages (e.g. issue modal submissions with metadata)
2326
# to reach the message handler instead of being silently dropped
2427
ignoring_self_events_enabled=False,
25-
oauth_settings=oauth_settings,
28+
oauth_settings=OAuthSettings(
29+
client_id=os.environ.get("SLACK_CLIENT_ID"),
30+
client_secret=os.environ.get("SLACK_CLIENT_SECRET"),
31+
scopes=BOT_SCOPES,
32+
user_scopes=USER_SCOPES,
33+
installation_store=installation_store,
34+
state_store=state_store,
35+
),
2636
)
2737

2838
register_listeners(app)

pydantic-ai/listeners/actions/account_connection.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ def handle_disconnect_account(
2121
"""Handle the Disconnect button click on App Home."""
2222
ack()
2323
try:
24-
from oauth import install_uri, oauth_settings
24+
from oauth import authorize_url_generator, installation_store, state_store
2525

2626
user_id = context.user_id
27-
oauth_settings.installation_store.delete_installation(
28-
enterprise_id=context.enterprise_id,
29-
team_id=context.team_id,
30-
user_id=user_id,
31-
)
32-
oauth_settings.installation_store.delete_bot
33-
view = build_app_home_view(authorize_url=install_uri)
27+
installation_store.delete_installation(
28+
enterprise_id=context.enterprise_id or "",
29+
team_id=context.team_id or "",
30+
user_id=user_id,
31+
)
32+
state = state_store.issue()
33+
authorize_url = authorize_url_generator.generate(state)
34+
view = build_app_home_view(authorize_url=authorize_url)
3435
client.views_publish(user_id=user_id, view=view)
3536
except Exception as e:
3637
logger.exception(f"Failed to handle disconnect: {e}")

pydantic-ai/listeners/events/app_home_opened.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ def handle_app_home_opened(client: WebClient, context: BoltContext, logger: Logg
1515
is_connected = False
1616

1717
if os.environ.get("SLACK_CLIENT_ID"):
18-
from oauth import install_uri
18+
from oauth import authorize_url_generator, installation_store, state_store
1919

20-
if context.authorize_result.user_token:
20+
installation = installation_store.find_installation(
21+
enterprise_id=context.enterprise_id or "",
22+
team_id=context.team_id or "",
23+
user_id=user_id,
24+
)
25+
if installation and installation.user_token:
2126
is_connected = True
2227
else:
23-
authorize_url = install_uri
28+
state = state_store.issue()
29+
authorize_url = authorize_url_generator.generate(state)
2430

2531
view = build_app_home_view(
2632
authorize_url=authorize_url, is_connected=is_connected

pydantic-ai/oauth.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import json
22
import os
33
from pathlib import Path
4-
from urllib.parse import urljoin
5-
from dotenv import load_dotenv
64

7-
8-
from slack_bolt.oauth.oauth_settings import OAuthSettings
5+
from slack_sdk.oauth import AuthorizeUrlGenerator
96
from slack_sdk.oauth.installation_store import FileInstallationStore
107
from slack_sdk.oauth.state_store import FileOAuthStateStore
118

12-
load_dotenv(dotenv_path=".env", override=False)
13-
149
_manifest = json.loads(Path("manifest.json").read_text())
1510
BOT_SCOPES = _manifest["oauth_config"]["scopes"]["bot"]
1611

@@ -25,18 +20,19 @@
2520
"users:read",
2621
]
2722

28-
oauth_settings = OAuthSettings(
29-
client_id=os.environ.get("SLACK_CLIENT_ID"),
30-
client_secret=os.environ.get("SLACK_CLIENT_SECRET"),
31-
redirect_uri=os.environ.get("SLACK_REDIRECT_URI"),
23+
installation_store = FileInstallationStore(
24+
base_dir="./data/installations",
25+
historical_data_enabled=False,
26+
)
27+
28+
state_store = FileOAuthStateStore(
29+
expiration_seconds=600,
30+
base_dir="./data/states",
31+
)
32+
33+
authorize_url_generator = AuthorizeUrlGenerator(
34+
client_id=os.environ.get("SLACK_CLIENT_ID", ""),
35+
redirect_uri=os.environ.get("SLACK_REDIRECT_URI", ""),
3236
scopes=BOT_SCOPES,
3337
user_scopes=USER_SCOPES,
34-
installation_store=FileInstallationStore(
35-
base_dir="./data/installations",
36-
),
37-
state_store=FileOAuthStateStore(
38-
expiration_seconds=600,
39-
base_dir="./data/states",
40-
),
4138
)
42-
install_uri = urljoin(oauth_settings.redirect_uri, oauth_settings.install_path)

0 commit comments

Comments
 (0)