Skip to content

API Reference parrot.auth.oauth2_routes

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.auth.oauth2_routes

View source

Generic OAuth 2.0 callback routes for AI-Parrot.

Each :class:parrot.auth.oauth2_base.AbstractOAuth2Manager subclass mounts a single callback route via :func:setup_oauth2_routes. The handler:

  • Validates code and state query parameters.
  • Locates the per-provider manager on the aiohttp app (app[f"oauth2_manager_{provider_id}"]).
  • Delegates the token exchange to manager.handle_callback(code, state).
  • For the web channel, persists the credential via :class:parrot.auth.oauth2.service.IntegrationsService and renders the existing web_oauth_success.html postMessage page.
  • For the A2A channel (FEAT-260 / TASK-1645): when state_payload["a2a_interaction_id"] is present, calls the registered A2A resume hook — typically :meth:~parrot.a2a.server.A2AServer.resume_from_oauth_callback — to reload the suspended execution and call agent.resume(). The hook is stored on the aiohttp app under app["a2a_oauth_resume_hook"] via :func:register_a2a_resume_hook. The package boundary (core ai-parrot vs. satellite ai-parrot-server) is respected: no direct import of :class:~parrot.a2a.server.A2AServer in this module.

The Jira-specific callback path at /api/auth/jira/callback is a compatibility alias for the generic Jira callback handler.

Alias CredentialPersistenceError

Re-exported from parrot.auth.oauth2_base.CredentialPersistenceError.

Alias IntegrationsService

Re-exported from parrot.auth.oauth2.service.IntegrationsService.

Alias WEB_OAUTH_ALLOWED_ORIGINS

Re-exported from parrot.conf.WEB_OAUTH_ALLOWED_ORIGINS.

Function handle_mcp_oauth2_callback

Handle OAuth2 callback for MCP server authorization code flows.

This route is called by the authorization server after the user grants access. It dispatches the authorization code to the waiting transport coroutine via the shared _pending_mcp_callbacks dict in :mod:parrot.mcp.oauth2_state.

Route: GET /api/auth/oauth2/mcp/callback

handle_mcp_oauth2_callback(request: web.Request) -> web.Response

Parameter Type Default Description
request web.Request

Returns: web.Response — HTML response with success or error message.

Alias is_pending

Re-exported from parrot.mcp.oauth2_state.is_pending.

Attribute logger

Function make_oauth2_callback

Return a request handler bound to provider_id.

make_oauth2_callback(provider_id: str)

Parameter Type Default Description
provider_id str

Function register_a2a_resume_hook

Register an async callable to resume suspended A2A tasks after OAuth.

The hook is called after a successful OAuth callback when state_payload contains an a2a_interaction_id field. It is called with the interaction_id as its only argument.

Typically wired as::

a2a_server = A2AServer(agent, ...)
register_a2a_resume_hook(
    app,
    a2a_server.resume_from_oauth_callback,
)

The indirection keeps the ai-parrot core package free of any import from the ai-parrot-server satellite.

register_a2a_resume_hook(app: web.Application, hook: Callable[[str], Coroutine[Any, Any, None]]) -> None

Parameter Type Default Description
app web.Application The aiohttp :class:~aiohttp.web.Application.
hook Callable[[str], Coroutine[Any, Any, None]] Async callable (interaction_id: str) -> None.

Alias resolve_pending_callback

Re-exported from parrot.mcp.oauth2_state.resolve_pending_callback.

Function setup_mcp_oauth2_callback

Register the MCP OAuth2 callback route on app.

Idempotent — calling twice is a no-op. The route is registered at /api/auth/oauth2/mcp/callback and excluded from auth middleware.

setup_mcp_oauth2_callback(app: web.Application) -> None

Parameter Type Default Description
app web.Application The aiohttp web application.

Function setup_oauth2_routes

Attach the OAuth2 callback route for provider_id to app.

Idempotent — calling twice with the same arguments is a no-op.

setup_oauth2_routes(app: web.Application, provider_id: str, callback_path: str) -> None

Parameter Type Default Description
app web.Application
provider_id str
callback_path str

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally