Skip to main content
This section covers the identity, authentication, and management layers of the Palyra ecosystem. The palyra-auth crate provides the low-level primitives for managing credentials and OAuth state, while the palyra-control-plane crate defines the models and client used for communication between the operator’s interface (CLI/Web Console) and the daemon.

palyra-auth: Authentication Primitives

The palyra-auth crate is responsible for the lifecycle of credentials used by the ModelProvider and other external integrations. It handles storage, validation, and background refreshing of OAuth tokens.

Auth Credentials and Registry

The AuthProfileRegistry is the central manager for AuthProfileRecord entities crates/palyra-auth/src/lib.rs#21. It supports various credential types including API keys and OAuth2 refresh tokens.
EntityRoleSource
AuthCredentialRepresents a raw secret or token.crates/palyra-auth/src/lib.rs#10-16
AuthProfileRecordA named identity containing credentials and metadata.crates/palyra-auth/src/lib.rs#10-16
AuthProfileScopeDefines if a profile is Global or scoped to a specific Principal.crates/palyra-auth/src/lib.rs#10-16
AuthHealthReportStatus of a credential (e.g., Valid, Expired, RateLimited).crates/palyra-auth/src/lib.rs#10-16
Sources: crates/palyra-auth/src/lib.rs#1-33, crates/palyra-auth/Cargo.toml#1-19

OAuth Refresh Logic

For providers like OpenAI that use OAuth2, the crate implements an automated refresh mechanism. The OAuthRefreshAdapter trait allows for provider-specific refresh implementations crates/palyra-auth/src/lib.rs#17-20. Sources: crates/palyra-auth/src/lib.rs#17-20

palyra-control-plane: Management Interface

The palyra-control-plane crate provides the high-level API client and data models used by the Web Console and CLI to manage the daemon.

Control Plane Client

The ControlPlaneClient is a high-level wrapper around reqwest that communicates with the daemon’s Admin API (/console/v1/*) crates/palyra-control-plane/src/client.rs#33-40. Sources: crates/palyra-control-plane/src/client.rs#1-215

Data Models

The models.rs file defines the JSON-serializable structures that form the Palyra API contract. Sources: crates/palyra-control-plane/src/models.rs#1-230

OpenAI Auth Integration

The daemon includes a specialized openai_auth.rs module for handling the OpenAI-specific OAuth flow. This module bridges the palyra-auth primitives with the OpenAI API requirements.

PKCE Flow and Token Exchange

The integration implements Proof Key for Code Exchange (PKCE) to secure the authorization code flow.
  1. Challenge Generation: generate_pkce_verifier() and pkce_challenge() create the necessary cryptographic strings crates/palyra-daemon/src/openai_auth.rs#99-107.
  2. Authorization URL: build_authorization_url() constructs the redirect to auth.openai.com crates/palyra-daemon/src/openai_auth.rs#109-130.
  3. Token Exchange: exchange_authorization_code() swaps the code for an access_token and refresh_token crates/palyra-daemon/src/openai_auth.rs#132-187.

Token Validation

The validate_openai_bearer_token() function performs a “smoke test” by calling the /v1/models endpoint to ensure the provided token is functional before saving it to the registry crates/palyra-daemon/src/openai_auth.rs#189-195. Sources: crates/palyra-daemon/src/openai_auth.rs#1-195

Objectives and Automation Management

Objectives represent long-running goals or “standing orders” assigned to agents. They are managed by the ObjectiveRegistry crates/palyra-daemon/src/objectives.rs#169-173.

Objective Structure

An ObjectiveRecord tracks the high-level intent and its current execution state.
FieldDescription
kindObjective, Heartbeat, StandingOrder, or Program.
stateDraft, Active, Paused, Cancelled, or Archived.
budgetConstraints on max_runs and max_tokens.
automationLinks the objective to the cron scheduler via ObjectiveAutomationBinding.
Sources: crates/palyra-daemon/src/objectives.rs#23-228, crates/palyra-daemon/src/transport/http/handlers/console/objectives.rs#19-31

Data Flow: Console to Objective Execution

The following diagram illustrates how an operator’s request in the Web Console flows through the Control Plane into the daemon’s objective registry and scheduler. Control Plane to Objective Flow Sources: crates/palyra-daemon/src/transport/http/handlers/console/objectives.rs#66-130, crates/palyra-daemon/src/objectives.rs#221-228, crates/palyra-control-plane/src/client.rs#89-91

Authentication and Session Flow

The console_login_handler manages the transition from an administrative principal and admin_token to a browser-based ConsoleSession secured by cookies and CSRF tokens.

Logic Flow: Console Authentication

Handoff Mechanism

The console_browser_handoff_handler allows the CLI to generate a short-lived URL that automatically logs a browser into the Web Console crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#127-159.
  1. Mint: CLI calls create_browser_handoff.
  2. Store: Daemon stores ConsoleBrowserHandoff with a 60s TTL crates/palyra-daemon/src/transport/http/handlers/console/auth.rs:5, 141-152.
  3. Consume: Browser navigates to /consume?token=..., which converts the handoff into a full ConsoleSession crates/palyra-daemon/src/transport/http/handlers/console/auth.rs:154-157, 161-170.
Sources: crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#19-170, crates/palyra-daemon/src/app/state.rs#156-170, crates/palyra-control-plane/src/models.rs#19-29