Skip to main content

Async Python SDK for Asgardeo AI agent authentication

Project description

Asgardeo AI SDK

Async Python SDK for Asgardeo AI agent authentication and on-behalf-of (OBO) token flows.

Features

  • Agent Authentication: Authenticate AI agents using agent credentials
  • On-Behalf-Of (OBO) Tokens: Get user tokens on behalf of authenticated agents
  • Async/Await Support: Full async implementation using httpx
  • Token Management: Handle token exchange, refresh, and revocation
  • Authorization URLs: Generate authorization URLs for user authentication flows

Installation

Install from local development:

pip install -e .

Quick Start

Basic Setup

import asyncio
from asgardeo import AsgardeoConfig
from asgardeo_ai import AgentAuthManager, AgentConfig

# Configure Asgardeo connection
config = AsgardeoConfig(
    base_url="https://api.asgardeo.io/t/your-organization",
    client_id="your_client_id", 
    redirect_uri="https://your-app.com/callback",
    client_secret="your_client_secret"
)

# Configure AI agent
agent_config = AgentConfig(
    agent_id="your_agent_id",
    agent_secret="your_agent_secret"
)

# Create auth manager
auth_manager = AgentAuthManager(config, agent_config)

Agent Authentication

async def main():
    async with AgentAuthManager(config, agent_config) as auth_manager:
        # Get token for the AI agent
        agent_token = await auth_manager.get_agent_token(["openid", "profile"])
        print(f"Agent access token: {agent_token.access_token}")

asyncio.run(main())

User Authorization Flow

async def user_auth_flow():
    async with AgentAuthManager(config, agent_config) as auth_manager:
        # Generate authorization URL for user
        scopes = ["openid", "profile", "email"]
        auth_url, state = auth_manager.get_authorization_url(scopes)
        
        print(f"Redirect user to: {auth_url}")
        
        # After user authorizes and you receive the auth code:
        # auth_code = "received_from_callback"
        
        # Get OBO token for the user
        obo_token = await auth_manager.get_obo_token(auth_code, scopes, agent_token)
        # print(f"User access token: {obo_token.access_token}")

API Reference

AgentAuthManager

Main class for handling agent authentication and OBO flows.

Methods

  • get_agent_token(scopes: Optional[List[str]] = None) -> OAuthToken: Get access token for the agent
  • get_authorization_url(scopes: List[str], state: Optional[str] = None) -> Tuple[str, str]: Generate authorization URL
  • get_obo_token(auth_code: str, agent_token: str, scopes: Optional[List[str]] = None) -> OAuthToken: Exchange auth code for user token

AgentConfig

Configuration for AI agent credentials.

  • agent_id: str: Agent identifier
  • agent_secret: str: Agent secret

Requirements

  • Python >= 3.10
  • httpx (for async HTTP)
  • asgardeo (base SDK)

Development

# Install dependencies
poetry install

# Build
poetry build

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asgardeo_ai-0.2.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asgardeo_ai-0.2.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file asgardeo_ai-0.2.0.tar.gz.

File metadata

  • Download URL: asgardeo_ai-0.2.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.10.18 Linux/6.11.0-1018-azure

File hashes

Hashes for asgardeo_ai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 edc3ce888ea18d10f7058443acc0b0e09ceb8e6268a3e8b8113b52c6fa05f497
MD5 2e50524b7d4839dd328c98a4972cabe1
BLAKE2b-256 265a8166a70ae585861cc0377d2c078559455217cc795e868328401e570e6aa4

See more details on using hashes here.

File details

Details for the file asgardeo_ai-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: asgardeo_ai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.10.18 Linux/6.11.0-1018-azure

File hashes

Hashes for asgardeo_ai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 faa6de6512c59b2ec0728b615740bc2da94c9a1724d2e7e4e66ab08a67edd6a6
MD5 c11246ac28baad4bdac7854f40d69467
BLAKE2b-256 4cf37dad557b616def31bcbd62f8a9e7dd66ff656e80e051c1740141dbc3aa74

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page