Skip to content

API Reference parrot.auth.broker.core

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

parrot.auth.broker.core

View source

The surface-agnostic :class:CredentialBroker (FEAT-264).

Alias AuditLedger

Re-exported from parrot.security.audit_ledger.AuditLedger.

Alias CanonicalIdentityMapper

Re-exported from parrot.auth.identity.CanonicalIdentityMapper.

Class CredentialBroker

Surface-agnostic per-user credential broker.

Owns a provider_id → resolver registry and resolves per-user credentials at tool-invocation time. On a successful resolution it appends a signed entry to the optional :class:~parrot.security.audit_ledger.AuditLedger; on a miss it returns :class:~parrot.auth.credentials.NeedsAuth (never raises on its own — the caller raises :class:~parrot.auth.credentials.CredentialRequired for surfaces to catch).

Usage

.. code-block:: python

broker = CredentialBroker.from_config(
    configs=[
        ProviderCredentialConfig(provider="workiq", auth="obo",
                                 options={"scope": "..."}),
    ],
    o365_interface=o365,
    o365_oauth_manager=mgr,
    vault=vault,
    audit_ledger=ledger,
)
result = await broker.resolve("workiq", "a2a:copilot", "user@example.com")
if isinstance(result, NeedsAuth):
    raise CredentialRequired(result.provider, result.auth_url, result.auth_kind)
Parameter Type Default Description
audit_ledger AuditLedger | None None Optional canonical :class:~parrot.security.audit_ledger.AuditLedger. When supplied a signed entry is appended on every successful resolution.
identity_mapper CanonicalIdentityMapper | None None Optional :class:~parrot.auth.identity.CanonicalIdentityMapper for cross-surface identity normalization.

Method CredentialBroker.register

Register a resolver for provider.

register(provider: str, resolver: CredentialResolver, auth_kind: str = 'oauth2') -> None

Parameter Type Default Description
provider str Provider identifier (e.g. "workiq").
resolver CredentialResolver :class:CredentialResolver for this provider.
auth_kind str 'oauth2' The authentication kind for this provider ("obo", "oauth2", "static_key", "mcp"). Stored alongside the resolver and returned in :class:~parrot.auth.credentials.NeedsAuth on a miss. Defaults to "oauth2" for backward compatibility with callers that do not supply an explicit kind.

Method CredentialBroker.from_config

Build a broker from a list of declarative provider configs.

This is a pure construction call — no I/O, safe to call from AbstractBot.configure().

from_config(configs: list[ProviderCredentialConfig], strict: bool = True, **deps: Any) -> CredentialBroker

Parameter Type Default Description
configs list[ProviderCredentialConfig] Declarative provider credential configurations.
strict bool True When True (default), a resolver build failure raises :class:CredentialBrokerConfigError immediately. When False, the failing provider is skipped with a warning and the broker is returned with the remaining providers.
**deps Any {} Runtime dependencies forwarded to :class:CredentialResolverFactory (e.g. vault, o365_interface, audit_ledger).

Returns: CredentialBroker — A fully-configured :class:CredentialBroker.

Raises:

  • CredentialBrokerConfigError — If strict=True and a resolver build fails for any provider.

Method CredentialBroker.resolve

Resolve the per-user credential for provider.

resolve(provider: str, channel: str, user_id: str, **ctx: Any) -> ResolvedCredential | NeedsAuth

Parameter Type Default Description
provider str Provider identifier.
channel str Invocation channel (e.g. "a2a:copilot"); used for audit context only (vault keyed by canonical identity).
user_id str Canonical per-user identity. If an identity_mapper is set it is applied first; otherwise the raw value is used.
**ctx Any {} Extra context forwarded to the resolver (e.g. tool_name).

Returns: ResolvedCredential | NeedsAuth — class:ResolvedCredential on success (audit entry appended) or class:NeedsAuth on a miss.

Raises:

  • KeyError — If no resolver is registered for provider (fail closed).
  • ValueError — If user_id is empty / None (fail closed).

Class CredentialBrokerConfigError

Raised by :meth:CredentialBroker.from_config in strict mode when a resolver cannot be built for a declared provider.

Inherits from Exception directly so callers can catch it without depending on any domain-specific base class.

Alias CredentialResolver

Re-exported from parrot.auth.credentials.CredentialResolver.

Alias CredentialResolverFactory

Re-exported from parrot.auth.broker.factory.CredentialResolverFactory.

Alias NeedsAuth

Re-exported from parrot.auth.credentials.NeedsAuth.

Alias ProviderCredentialConfig

Re-exported from parrot.auth.credentials.ProviderCredentialConfig.

Alias ResolvedCredential

Re-exported from parrot.auth.credentials.ResolvedCredential.

Attribute logger

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