import os
from dataclasses import replace
import httpx
from agentjam import oauth_connection
from agentjam.oauth import OAuthEndpoints, TokenError, TokenResponse, construct_standard_profile
def construct_params(scopes: dict[str, list[str]]) -> dict[str, str]:
return {"scope": ",".join(scopes.get("default", []))}
def read_error(response: httpx.Response, body: TokenResponse) -> TokenError | None:
return TokenError(code=str(body["error"])) if body.get("ok") is False else None
standard = construct_standard_profile(
OAuthEndpoints(
authorize="https://chat.example.com/oauth/authorize",
token="https://chat.example.com/api/oauth.access",
)
)
chat = oauth_connection(
provider="chat",
scopes=["chat:write"],
client_id=os.environ["CHAT_CLIENT_ID"],
client_secret=os.environ["CHAT_CLIENT_SECRET"],
redirect_uri="https://inbox.example.com/oauth/callback",
store=store,
profile=replace(
standard,
pkce=False,
construct_authorize_params=construct_params,
read_error=read_error,
),
)