Skip to content

API Reference parrot.auth.credentials

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

parrot.auth.credentials

View source

Credential resolution abstractions for toolkits.

:class:CredentialResolver is the bridge between a toolkit and its credential storage. It hides whether credentials come from a static configuration (legacy basic auth / PAT) or from a per-user OAuth 2.0 token store backed by Redis, allowing toolkits to simply call resolver.resolve(channel, user_id) without knowing the scheme.

Two concrete resolvers are provided:

  • :class:OAuthCredentialResolver: delegates to a :class:JiraOAuthManager (or any object that exposes get_valid_token / create_authorization_url).
  • :class:StaticCredentialResolver: always returns the same :class:StaticCredentials — used for the existing basic_auth and token_auth modes so legacy toolkits keep working unchanged.

FEAT-264 additions

  • :class:ProviderCredentialConfig — declarative per-provider credential config (AgentDefinition / manifest).
  • :class:ResolvedCredential — credential material resolved from vault (secret never logged; only the key_fingerprint is recorded in the audit ledger).
  • :class:NeedsAuth — surface-neutral miss signal returned by the broker.
  • :class:CredentialRequired — exception raised by the tool-loop seam when the broker returns NeedsAuth; surfaces catch it to render their UX.

Attribute AuthKind

Class AuthRequiredPayload

Unified needs-auth payload serialized by ToolManager and AgentTalk.

Fields:

Field Type Default Description
provider str
auth_url Optional[str] None
scopes List[str]
tool_name Optional[str] None
message str ''
auth_kind Optional[AuthKind] None
user_code Optional[str] None
verification_uri Optional[str] None
expires_in Optional[int] None

Class CredentialRequired

Raised by the tool-loop seam when the broker returns :class:NeedsAuth.

This is the canonical, surface-neutral exception. Each surface catches it and renders the appropriate UX:

  • A2A: suspend + TEXT consent link.
  • MSAgentSDK: Adaptive Card (static key) or OAuthCard (OAuth/OBO).
  • CLI: plain URL printed to stdout.
Parameter Type Default Description
provider str Provider identifier.
auth_url str Consent / OOB capture URL (NEVER a secret).
auth_kind str Auth kind for surface rendering.
user_code Optional[str] None Device-code flow only (FEAT-266, keyword-only) — the short code the user enters at verification_uri.
verification_uri Optional[str] None Device-code flow only (FEAT-266, keyword-only) — the Microsoft device-login URL.
expires_in Optional[int] None Device-code flow only (FEAT-266, keyword-only) — seconds until the device code expires.

Method CredentialRequired.to_payload

Serialize to the unified needs-auth payload.

to_payload(*, tool_name: Optional[str] = None) -> AuthRequiredPayload

Parameter Type Default Description
tool_name Optional[str] None

Returns: AuthRequiredPayload

Class CredentialResolver

Resolves credentials for a given channel/user pair.

Method CredentialResolver.resolve

Return credentials for (channel, user_id) or None.

None indicates the user has not authorized yet and the caller should surface an authorization URL (see :meth:get_auth_url).

resolve(channel: str, user_id: str) -> Optional[Any]

Parameter Type Default Description
channel str
user_id str

Returns: Optional[Any]

Method CredentialResolver.get_auth_url

Return the authorization URL the user should follow.

get_auth_url(channel: str, user_id: str) -> str

Parameter Type Default Description
channel str
user_id str

Returns: str

Method CredentialResolver.is_connected

Return True when :meth:resolve currently yields credentials.

is_connected(channel: str, user_id: str) -> bool

Parameter Type Default Description
channel str
user_id str

Returns: bool

Class NeedsAuth

Surface-neutral miss signal from the broker.

Fields:

Field Type Default Description
provider str Provider identifier.
auth_url str Consent / OOB capture URL the user must visit. NEVER a secret.
auth_kind AuthKind Drives surface rendering (card type).
user_code Optional[str] None Device-code flow only (FEAT-266) — the short code the user enters at verification_uri. None for non-device-code auth kinds.
verification_uri Optional[str] None Device-code flow only (FEAT-266) — the Microsoft device-login URL. None for non-device-code auth kinds.
expires_in Optional[int] None Device-code flow only (FEAT-266) — seconds until the device code expires. None for non-device-code auth kinds.

Class OAuthCredentialResolver

Resolves credentials from an OAuth 2.0 token store.

The resolver delegates all lookups to a manager that implements get_valid_token(channel, user_id) and create_authorization_url(channel, user_id). The reference implementation is :class:JiraOAuthManager, but any compatible object (e.g., a future GitHub or O365 manager) can be plugged in.

Parameter Type Default Description
oauth_manager Any
principal_resolver Optional['PrincipalResolver'] None

Method OAuthCredentialResolver.resolve

resolve(channel: str, user_id: str) -> Optional[Any]

Parameter Type Default Description
channel str
user_id str

Returns: Optional[Any]

Method OAuthCredentialResolver.get_auth_url

get_auth_url(channel: str, user_id: str) -> str

Parameter Type Default Description
channel str
user_id str

Returns: str

Alias PermissionContext

Re-exported from parrot.auth.permission.PermissionContext.

Alias Principal

Re-exported from parrot.auth.principal.Principal.

Alias PrincipalResolver

Re-exported from parrot.auth.principal.PrincipalResolver.

Class ProviderCredentialConfig

Declarative per-provider credential config (AgentDefinition / manifest).

Fields:

Field Type Default Description
provider str Provider identifier (e.g. "workiq", "fireflies").
auth AuthKind Auth kind — selects the resolver strategy in :class:~parrot.auth.broker.CredentialResolverFactory.
options Dict[str, Any] Extra options forwarded to the strategy constructor (e.g. scope, vault_key, capture_url).

Class ResolvedCredential

Credential material returned by the broker on a successful resolution.

Fields:

Field Type Default Description
provider str Provider identifier.
secret Any Raw credential (token, API key, …). NEVER log this field; only :attr:key_fingerprint should appear in audit records.
key_fingerprint str SHA-256 hex digest of secret (for audit).

Class StaticCredentialResolver

Returns a fixed :class:StaticCredentials instance.

Used for basic_auth / token_auth modes where a single service-account credential is shared across all users. The resolver ignores channel and user_id.

Parameter Type Default Description
server_url str
username Optional[str] None
password Optional[str] None
token Optional[str] None
auth_type str 'basic_auth'

Method StaticCredentialResolver.resolve

resolve(channel: str, user_id: str) -> StaticCredentials

Parameter Type Default Description
channel str
user_id str

Returns: StaticCredentials

Method StaticCredentialResolver.get_auth_url

get_auth_url(channel: str, user_id: str) -> str

Parameter Type Default Description
channel str
user_id str

Returns: str

Class StaticCredentials

Credential bundle for non-OAuth (legacy) toolkit modes.

Parameter Type Default Description
server_url str
username Optional[str] None
password Optional[str] None
token Optional[str] None
auth_type str 'basic_auth'

Fields:

Field Type Default Description
server_url str
username Optional[str] None
password Optional[str] None
token Optional[str] None
auth_type str 'basic_auth'

Function credential_channel_user_id

Return the channel identity an OAuth toolkit must use for credential lookup.

Teams requires the explicit, trusted context.channel_user_id (the AAD oid); every other channel keeps the existing behaviour of using context.user_id.

credential_channel_user_id(context: 'PermissionContext') -> Optional[str]

Parameter Type Default Description
context 'PermissionContext' The caller's permission context.

Returns: Optional[str] — The lookup identity, or None when a Teams context carries no channel identity (fail closed).

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