AuthSec AI — LlamaIndex Integration
Reader-based ingestion — a custom BaseReader authenticates with AuthSec, fetches restricted records from a protected API, and indexes them into a LlamaIndex VectorStoreIndex for RAG queries.
Architecture
LlamaIndex Reader (custom_reader.py) — BaseReader subclass
↓
authsec_helper.py — thin wrapper, MOCK fallback, debug logging
↓
authsec-langchain-sdk — official SDK (PyPI)
↓
AuthSec Delegation Backend
↓
Short-lived JWT (RS256, scoped, SPIFFE-identified)
↓
Protected API (with Authorization: Bearer header)
The official SDK owns the entire delegation-token lifecycle.
authsec_helper.py is a thin, framework-agnostic wrapper that adds MOCK fallback and structured console logging — it never reimplements the token exchange itself.
File Structure
| File | Role |
|---|---|
authsec_helper.py |
Thin wrapper around authsec-langchain-sdk; MOCK fallback, debug logging |
custom_reader.py |
LlamaIndex BaseReader subclass — AuthSecSecureReader |
main.py |
Entry point; ingestion + VectorStoreIndex + query demo |
requirements.txt |
Dependencies including authsec-langchain-sdk |
Prerequisites
| Requirement | Details |
|---|---|
| Python | 3.10 or later |
| AuthSec account | Registered AI agent client on the AuthSec dashboard |
| Trust delegation | Created with target type "Langchain AI agent" |
authsec-langchain-sdk |
pip install authsec-langchain-sdk |
Installation & Setup
cd integrations/llamaindex
pip install -r requirements.txt
requirements.txt pulls in llama-index-core, requests, authsec-langchain-sdk, and supporting packages.
Running the Demo
MOCK Mode — zero setup
python main.py
No environment variables required. When AUTHSEC_BASE_URL and AUTHSEC_AGENT_CLIENT_ID are absent, the wrapper falls back to an offline mock mode with demo data. Useful for exploring the integration pattern without an AuthSec account.
LIVE Mode — against production
# Windows PowerShell
$env:AUTHSEC_BASE_URL = "https://prod.api.authsec.ai"
$env:AUTHSEC_AGENT_CLIENT_ID = "your-agent-client-uuid"
$env:OPENAI_API_KEY = "sk-..." # optional — enables real LLM queries
python main.py
# bash / zsh
export AUTHSEC_BASE_URL="https://prod.api.authsec.ai"
export AUTHSEC_AGENT_CLIENT_ID="your-agent-client-uuid"
export OPENAI_API_KEY="sk-..."
python main.py
When OPENAI_API_KEY is set, main.py builds a real VectorStoreIndex and runs natural-language queries against the ingested documents. Without it, the demo runs a high-fidelity simulation that still exercises the real AuthSec token flow and document parsing.
Example Output (LIVE mode, verified against production)
[AuthSec SDK] -- Initializing AuthSec Client (LlamaIndex) ----------
[AuthSec SDK] [Mode] LIVE — using official authsec-langchain-sdk
|- Base URL : https://prod.api.authsec.ai
|- Client ID : fe6d5a81-58ac-4c4b-85fa-f84b6c9cb73d
[AuthSec SDK] [Init] Official authsec-langchain-sdk client initialized.
[AuthSec SDK] [Delegation] Requesting delegation token via official authsec-langchain-sdk...
[AuthSec SDK] [Success] LIVE delegation token acquired via official SDK.
|- Token : eyJhbGciOiJSUzI1NiIsInR5...
How the Integration Works
-
Custom Reader subclass —
AuthSecSecureReader(incustom_reader.py) inherits from LlamaIndex'sBaseReader, making it plug-and-play with any ingestion pipeline. -
SDK initialization — when
AuthSecSecureReaderis constructed, its internalAuthSecClientreadsAUTHSEC_BASE_URLandAUTHSEC_AGENT_CLIENT_IDand initializes anAuthsecClientfrom the officialauthsec-langchain-sdk. -
load_data()call — the pipeline callsreader.load_data(endpoint=..., scope=...). Inside, the reader requests a delegation token:GET /authsec/uflow/sdk/delegation-token?client_id=<uuid>The SDK handles the exact request contract required by the AuthSec backend (Trust Delegation target type: "Langchain AI agent").
-
Downstream API call — the JWT is passed as
Authorization: Bearer <token>to the protected endpoint viaclient.request_secure_api(). -
Document construction — the returned JSON is parsed into LlamaIndex
Documentobjects with security-stamped metadata (source_endpoint,ingestion_auth,clearance_required). -
Vector indexing —
main.pyfeeds the documents into aVectorStoreIndex. Chunks are embedded and stored for retrieval. -
RAG query — natural-language questions are resolved against the secured, indexed data — producing authenticated, source-attributed answers.
Environment Variables Reference
| Variable | Required | Description |
|---|---|---|
AUTHSEC_BASE_URL |
Yes (LIVE) | AuthSec server root, e.g. https://prod.api.authsec.ai |
AUTHSEC_AGENT_CLIENT_ID |
Yes (LIVE) | Agent's client UUID from the AuthSec dashboard |
OPENAI_API_KEY |
Optional | Enables real LLM embeddings and queries; simulation runs without it |
Security Model
AuthSec replaces static, long-lived API keys with short-lived delegation tokens. Each token is a signed RS256 JWT scoped to the specific permissions granted through the trust delegation. Tokens expire automatically — the SDK refreshes them transparently — so there is no secret to rotate or leak into version control.
Every delegation token carries a SPIFFE identity (spiffe://authsec.dev/ns/default/sa/ai-agent) that cryptographically binds the token to a specific agent workload. Downstream APIs verify both the JWT signature and the SPIFFE subject, establishing a chain of trust from the AuthSec backend through the SDK to the protected resource.
This model means the AI agent never handles raw credentials for the target API. The AuthSec backend acts as a trust broker: it evaluates the delegation policy, mints a scoped token, and the agent simply presents that token. Revoking access is a single dashboard action — no credential rotation required.
Debug Logging
The wrapper emits structured, colour-coded console output under the [AuthSec SDK] prefix:
| Prefix | Meaning |
|---|---|
[Mode] LIVE |
SDK initialized, env vars detected |
[Mode] MOCK |
No env vars — running offline |
[Init] |
SDK client construction result |
[Delegation] |
Token request in progress |
[Success] |
Token acquired or API call succeeded |
[Error] |
SDK call failed — fallback triggered |
[Token] … [MOCK FALLBACK] |
Using locally generated mock JWT |
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
404 Client not found |
client_id not registered, or trust delegation not created |
Verify the UUID on the AuthSec dashboard; ensure a trust delegation exists with target type "Langchain AI agent" |
ImportError: authsec_langchain |
SDK not installed | pip install authsec-langchain-sdk |
| SSL / connection errors | Wrong URL scheme or unreachable host | Confirm AUTHSEC_BASE_URL uses https:// for production |
400 Invalid client_id format |
Trailing whitespace or characters in UUID | Check for copy-paste artefacts in the env var |
A Note on secure-vault/… Endpoints
The
secure-vault/metrics,secure-vault/records, etc. endpoints used in this demo are illustrative mock resources. They are intentionally not hosted onprod.api.authsec.ai. The delegation token flow succeeds against production — you will see a valid JWT returned — but the subsequent call tosecure-vault/*will return a 404. This is expected behaviour, not a bug. In a real deployment you would replace these paths with your own protected API endpoints.
Further Reading
Metadata
Release files for authsec-llamaindex 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| authsec_llamaindex-0.1.0.tar.gz | 12.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| authsec_llamaindex-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.7 kB
Release files / authsec_llamaindex-0.1.0.tar.gz
| Download URL | authsec_llamaindex-0.1.0.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5030adaffcd65c553ebba988364e339fdbed219e94e749c2fee32a8d29253bd
|
|
BLAKE2b-256 checksum How to use checksums |
00ef73ba182b0edec95ef75aa7971659ac26b9e0c45e4b45d1b2565fbb0f4e10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.3
|
Release files / authsec_llamaindex-0.1.0-py3-none-any.whl
| Download URL | authsec_llamaindex-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a54059f623c82fe60611bdb40e1d4f37fafea6ebd0e73c9ce2407a6e0fcf474c
|
|
BLAKE2b-256 checksum How to use checksums |
0b464199d5c62276543b88809c8a4fe5f2d0c04cf63b4491453ece9f992c9d81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.3
|
Security for authsec-llamaindex 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.