badge-checkValidate Delegation Token

Validate delegation tokens in receiving services using a minimal, lightweight gateway.

circle-info

When to use: When a service receives a request from an agent and needs to verify the delegation token before processing it.

chevron-rightPrerequisiteshashtag

5-Line Core

from gl_iam import IAMGateway
from gl_iam.providers.postgresql import PostgreSQLAgentProvider, PostgreSQLConfig

provider = PostgreSQLAgentProvider(PostgreSQLConfig(database_url="postgresql+asyncpg://user:pass@localhost/mydb", secret_key="your-secret-key-min-32-chars-long!", default_org_id="default"))
gateway = IAMGateway.for_agent_auth(agent_provider=provider, secret_key="your-secret-key-min-32-chars-long!")
result = await gateway.validate_delegation_token(token="eyJhbGciOi...")
delegation = result.unwrap()  # DelegationToken with chain, scope, task
circle-exclamation

Cross-Service Validation Architecture

Delegation tokens are stateless JWTs — the receiving service only needs the shared secret_key to validate, with no network call back to the issuing service.

Step-by-Step

1

Setup Receiving Service Gateway

Use IAMGateway.for_agent_auth() — a minimal gateway that only needs an agent provider and the shared secret_key. This enables cross-service token validation without requiring access to the full user database:

circle-info

The secret_key must match the key used by the service that created the delegation token. This is how cross-service validation works — shared secret, no network call.

2

Validate Token

3

Inspect the Delegation

After validation, inspect the chain, scope, and task:

4

Enforce Authorization

Validation confirms the token is authentic — your service must still enforce authorization:

circle-check

Complete Example

Create validate_delegation_token.py:

Run it:

Expected output:

Common Pitfalls

Pitfall
Solution

Different secret_key

The validating service must use the same secret_key as the issuing service

Token expired

Check delegation.expires_at — tokens have a finite lifetime set by expires_in_seconds

Token tampered

JWT signature verification will fail — the Result will contain the error

Not checking scopes after validation

Validation only proves authenticity. You must still check delegation.scope.scopes for authorization.

Assuming suspension is checked

Stateless validation does not check agent status. Query the provider for real-time checks.

Next Steps


circle-info

Found an issue on this page? Report it on our feedback formarrow-up-right.

Last updated

Was this helpful?