Agentic Identity Framework abstracting Keycloak/OIDC complexity for AI Agents
Project description
SecureAgent
A "Convention over Configuration" Python package for adding Agentic Identity to your AI Agents.
This package abstracts away the complexity of:
- Dynamic Client Registration: Automatically registers your agent with Keycloak if no credentials exist.
- Token Exchange: Implements RFC 8693 logic to exchange user tokens for downstream service access.
- Token Verification: Provides FastAPI dependencies to validate incoming Bearer tokens.
- Token Caching: Automatic token caching with refresh-before-expiry logic.
- Async Support: Non-blocking async methods for FastAPI and aiohttp.
- CLI Tools: Bootstrap credentials easily with
secureagent init.
Installation
pip install SecureAgent
Note: You may need to install from source or a private repository until published.
Quick Start with CLI
Bootstrap your agent's credentials using the CLI:
secureagent init --realm-url http://localhost:8080 --client-id my-agent
This will prompt for an Initial Access Token and create credentials.json.
Usage
Initialization
Initialize the security module with your realm URL and service details.
from SecureAgent import AgentSecurity
security = AgentSecurity(
realm_url="http://localhost:8080",
service_name="my-specialist-agent",
# initial_access_token is required only for first run to register the client
initial_access_token="<YOUR_INITIAL_ACCESS_TOKEN>",
# Optional: graceful degradation for development
fail_open=False, # Set True to return None instead of raising on errors
cache_tokens=True # Automatic token caching (default: True)
)
Getting a Token (Client Credentials Flow)
# Synchronous
token = security.get_token()
# Asynchronous (for FastAPI, aiohttp, etc.)
token = await security.get_token_async()
Protecting an Endpoint
Use the verify_token dependency to protect your FastAPI routes.
from fastapi import FastAPI, Depends
app = FastAPI()
@app.get("/secure-data")
def secure_endpoint(token_payload = Depends(security.verify_token)):
return {
"user": token_payload["sub"],
"message": "You have access!"
}
Exchanging Tokens (The Orchestrator Pattern)
If your agent needs to call another agent, use exchange_token.
# Synchronous
downstream_token = security.exchange_token(
user_token=user_token,
target_client="target-service"
)
# Asynchronous
downstream_token = await security.exchange_token_async(
user_token=user_token,
target_client="target-service"
)
# Use the new token to make the request
headers = {"Authorization": f"Bearer {downstream_token}"}
Cache Management
# Clear all cached tokens
security.clear_cache()
# Clear specific cache entry
security.clear_cache("client_credentials")
CLI Commands
| Command | Description |
|---|---|
secureagent init |
Register a new client and create credentials |
secureagent status |
Check credentials and Keycloak connectivity |
secureagent token |
Get an access token (for scripting) |
Configuration Options
| Parameter | Default | Description |
|---|---|---|
realm_url |
required | Keycloak server URL |
service_name |
required | Client ID for this agent |
realm_name |
"agent-mesh" |
Keycloak realm name |
creds_file |
"credentials.json" |
Path to store credentials |
fail_open |
False |
Return None instead of raising on errors |
cache_tokens |
True |
Enable automatic token caching |
cache_refresh_buffer |
30 |
Seconds before expiry to refresh |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file secureagent-0.1.3.tar.gz.
File metadata
- Download URL: secureagent-0.1.3.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23d93a96e2ea28a27c7fc32d4fb3039ecb1f4da284616c2012a6c137546d2a9e
|
|
| MD5 |
4538c5644a16dfad62b39ea127b46e6e
|
|
| BLAKE2b-256 |
e8c3884296d4f9b33db3c47545ef7f4119fe07f1be2b3f5383a0bf2f698b08b6
|
Provenance
The following attestation bundles were made for secureagent-0.1.3.tar.gz:
Publisher:
test.yml on armstrongsam25/SecureAgent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
secureagent-0.1.3.tar.gz -
Subject digest:
23d93a96e2ea28a27c7fc32d4fb3039ecb1f4da284616c2012a6c137546d2a9e - Sigstore transparency entry: 761704941
- Sigstore integration time:
-
Permalink:
armstrongsam25/SecureAgent@bb60ccbb3541477430d9118c697009cc8e346221 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/armstrongsam25
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test.yml@bb60ccbb3541477430d9118c697009cc8e346221 -
Trigger Event:
push
-
Statement type:
File details
Details for the file secureagent-0.1.3-py3-none-any.whl.
File metadata
- Download URL: secureagent-0.1.3-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e785b8c7b58a06da7c603ce0568f63adf057efbc86d1152b6a4403721bd6deb9
|
|
| MD5 |
ab019750e4123e0c8af02b16febbd06f
|
|
| BLAKE2b-256 |
d2b034f5a17e5868a669c492499d34d3acdd0e512272168ae0a3d6cbae75e166
|
Provenance
The following attestation bundles were made for secureagent-0.1.3-py3-none-any.whl:
Publisher:
test.yml on armstrongsam25/SecureAgent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
secureagent-0.1.3-py3-none-any.whl -
Subject digest:
e785b8c7b58a06da7c603ce0568f63adf057efbc86d1152b6a4403721bd6deb9 - Sigstore transparency entry: 761704949
- Sigstore integration time:
-
Permalink:
armstrongsam25/SecureAgent@bb60ccbb3541477430d9118c697009cc8e346221 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/armstrongsam25
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test.yml@bb60ccbb3541477430d9118c697009cc8e346221 -
Trigger Event:
push
-
Statement type: