Skip to content

API Reference parrot_tools.interfaces.gigsmart.auth

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

parrot_tools.interfaces.gigsmart.auth

View source

GigSmart OAuth 2.1 authentication — token lifecycle management.

Supports two grant types:

  • client_credentials (server-to-server) — read-only scopes, 15 min tokens. Tokens are obtained via HTTP Basic auth to /oauth/token.
  • auth_code + PKCE (user-facing) — full read+write access, 1 h tokens. Requires a user authorisation step; exchange code at /oauth/token with code_verifier.

Pre-configured refresh tokens (from GIGSMART_REFRESH_TOKEN) allow headless agents to obtain write access without an interactive OAuth flow.

Token caching is in-memory; an asyncio.Lock prevents concurrent refreshes. Write-scope enforcement raises GigSmartAuthError when a write operation is attempted with a token that only has read scopes.

Class GigSmartAuth

OAuth 2.1 token lifecycle manager for the GigSmart API.

Example::

auth = GigSmartAuth(config)
token = await auth.get_token(scopes=["read:gigs"])
headers = await auth.build_headers()
Parameter Type Default Description
config GigSmartConfig GigSmartConfig instance carrying client credentials and endpoints.

Method GigSmartAuth.get_token

Return a valid access token, refreshing proactively if needed.

get_token(scopes: list[str] | None = None) -> str

Parameter Type Default Description
scopes list[str] | None None Optional list of OAuth scopes required for this call. If not specified, uses the token's cached scopes.

Returns: str — The current access token string.

Raises:

  • GigSmartAuthError — If token acquisition fails or the requested scopes are unavailable for the configured grant type.

Method GigSmartAuth.build_headers

Return HTTP headers with a valid Bearer token.

build_headers() -> dict[str, str]

Returns: dict[str, str] — A dict containing the Authorization header.

Method GigSmartAuth.ensure_scope

Assert that the current token grants scope, raising otherwise.

Validates both that the token has the scope and that the grant type supports it (write scopes require auth_code, not client_credentials).

ensure_scope(scope: str) -> None

Parameter Type Default Description
scope str A single scope string to check, e.g. "write:gigs".

Raises:

  • GigSmartAuthError — When the current grant type does not allow the requested write scope.

Method GigSmartAuth.refresh_token

Force a token refresh using the cached refresh_token.

refresh_token() -> str

Returns: str — The new access token string.

Raises:

  • GigSmartAuthError — If no refresh token is available or the refresh request fails.

Method GigSmartAuth.generate_pkce_pair

Generate a PKCE (code_verifier, code_challenge) pair.

The code challenge uses SHA-256 hashed, base64url-encoded verifier (code_challenge_method=S256).

generate_pkce_pair() -> tuple[str, str]

Returns: tuple[str, str] — A (code_verifier, code_challenge) tuple of URL-safe strings.

Method GigSmartAuth.build_authorize_url

Build the OAuth authorisation URL for the auth_code + PKCE flow.

build_authorize_url(redirect_uri: str, scopes: list[str], code_challenge: str, state: str | None = None) -> str

Parameter Type Default Description
redirect_uri str The URI where the user will be sent after authorisation.
scopes list[str] List of OAuth scopes to request.
code_challenge str The PKCE code challenge (base64url SHA-256 of verifier).
state str | None None Optional opaque state string for CSRF protection.

Returns: str — The fully-formed authorisation URL string.

Method GigSmartAuth.exchange_code

Exchange an authorisation code for an access token (auth_code+PKCE).

exchange_code(code: str, redirect_uri: str, code_verifier: str) -> str

Parameter Type Default Description
code str The authorisation code received from the redirect.
redirect_uri str Must match the URI used in :meth:build_authorize_url.
code_verifier str The PKCE code verifier generated alongside the challenge.

Returns: str — The new access token string.

Raises:

  • GigSmartAuthError — If the exchange fails.

Method GigSmartAuth.close

Close the persistent token-fetch session.

close() -> None

Alias GigSmartAuthError

Re-exported from parrot_tools.interfaces.gigsmart.exceptions.GigSmartAuthError.

Alias GigSmartConfig

Re-exported from parrot_tools.interfaces.gigsmart.config.GigSmartConfig.

Alias GigSmartError

Re-exported from parrot_tools.interfaces.gigsmart.exceptions.GigSmartError.

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