authzai 0.2.1__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. {authzai-0.2.1/authzai.egg-info → authzai-0.4.0}/PKG-INFO +1 -1
  2. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/__init__.py +1 -1
  3. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/deps.py +62 -0
  4. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/service_deps.py +12 -0
  5. authzai-0.4.0/agentic_auth/api/v1/agent_clients.py +65 -0
  6. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/authorize.py +70 -0
  7. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/consent.py +4 -2
  8. authzai-0.4.0/agentic_auth/api/v1/sandbox.py +181 -0
  9. authzai-0.4.0/agentic_auth/api/v1/stepup.py +86 -0
  10. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/token.py +2 -0
  11. authzai-0.4.0/agentic_auth/api/v1/well_known.py +33 -0
  12. authzai-0.4.0/agentic_auth/boundary/__main__.py +101 -0
  13. authzai-0.4.0/agentic_auth/boundary/egress.py +229 -0
  14. authzai-0.4.0/agentic_auth/boundary/mcp.py +420 -0
  15. authzai-0.4.0/agentic_auth/boundary/resource.py +204 -0
  16. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/cli/__init__.py +2 -0
  17. authzai-0.4.0/agentic_auth/cli/sandbox.py +128 -0
  18. authzai-0.4.0/agentic_auth/coldstart/__init__.py +20 -0
  19. authzai-0.4.0/agentic_auth/coldstart/propose.py +212 -0
  20. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/config.py +69 -0
  21. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/embedded/__init__.py +18 -14
  22. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/embedded/_schema.py +6 -7
  23. authzai-0.4.0/agentic_auth/embedded/idp.py +137 -0
  24. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/errors.py +42 -0
  25. authzai-0.4.0/agentic_auth/gateway/__init__.py +16 -0
  26. authzai-0.4.0/agentic_auth/gateway/__main__.py +44 -0
  27. authzai-0.4.0/agentic_auth/gateway/app.py +365 -0
  28. authzai-0.4.0/agentic_auth/gateway/config.py +341 -0
  29. authzai-0.4.0/agentic_auth/gateway/metrics.py +86 -0
  30. authzai-0.4.0/agentic_auth/gateway/resolve.py +98 -0
  31. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/main.py +10 -1
  32. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/__init__.py +1 -0
  33. authzai-0.4.0/agentic_auth/models/agent_client.py +58 -0
  34. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/audit_decision.py +5 -0
  35. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/session.py +14 -0
  36. authzai-0.4.0/agentic_auth/oauth/__init__.py +6 -0
  37. authzai-0.4.0/agentic_auth/oauth/metadata.py +124 -0
  38. authzai-0.4.0/agentic_auth/oauth/resource.py +466 -0
  39. authzai-0.4.0/agentic_auth/oauth/validate.py +334 -0
  40. authzai-0.4.0/agentic_auth/repositories/agent_clients.py +93 -0
  41. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/repositories/audit_decisions.py +4 -0
  42. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/repositories/compiled_policies.py +16 -0
  43. authzai-0.4.0/agentic_auth/repositories/sandbox_runs.py +103 -0
  44. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/repositories/sessions.py +6 -0
  45. authzai-0.4.0/agentic_auth/repositories/step_up_grants.py +78 -0
  46. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/agent.py +5 -1
  47. authzai-0.4.0/agentic_auth/schemas/agent_client.py +33 -0
  48. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/audit.py +5 -0
  49. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/common.py +14 -0
  50. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/consent.py +39 -5
  51. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/reconciliation.py +11 -0
  52. authzai-0.4.0/agentic_auth/schemas/sandbox.py +133 -0
  53. authzai-0.4.0/agentic_auth/schemas/stepup.py +92 -0
  54. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sdk/client.py +12 -1
  55. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/audit.py +6 -0
  56. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/catalog_service.py +16 -0
  57. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/chain_query.py +4 -0
  58. authzai-0.4.0/agentic_auth/services/client_mapping.py +92 -0
  59. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/discovery.py +50 -1
  60. authzai-0.4.0/agentic_auth/services/guarantee.py +162 -0
  61. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/manifest_service.py +20 -3
  62. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/metrics.py +11 -0
  63. authzai-0.4.0/agentic_auth/services/principal.py +133 -0
  64. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/reconciler.py +72 -1
  65. authzai-0.4.0/agentic_auth/services/sandbox.py +281 -0
  66. authzai-0.4.0/agentic_auth/services/sessions.py +447 -0
  67. authzai-0.4.0/agentic_auth/services/stepup.py +382 -0
  68. authzai-0.4.0/agentic_auth/services/stepup_rules.py +72 -0
  69. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/tokens/exchange.py +5 -0
  70. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sidecar/config.py +18 -1
  71. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sidecar/enforce.py +13 -4
  72. {authzai-0.2.1 → authzai-0.4.0/authzai.egg-info}/PKG-INFO +1 -1
  73. {authzai-0.2.1 → authzai-0.4.0}/authzai.egg-info/SOURCES.txt +33 -0
  74. {authzai-0.2.1 → authzai-0.4.0}/pyproject.toml +4 -0
  75. authzai-0.2.1/agentic_auth/embedded/idp.py +0 -78
  76. authzai-0.2.1/agentic_auth/services/principal.py +0 -143
  77. authzai-0.2.1/agentic_auth/services/sessions.py +0 -231
  78. {authzai-0.2.1 → authzai-0.4.0}/LICENSE +0 -0
  79. {authzai-0.2.1 → authzai-0.4.0}/NOTICE +0 -0
  80. {authzai-0.2.1 → authzai-0.4.0}/README.md +0 -0
  81. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/_extras.py +0 -0
  82. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/__init__.py +0 -0
  83. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/errors.py +0 -0
  84. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/responses.py +0 -0
  85. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/__init__.py +0 -0
  86. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/agents.py +0 -0
  87. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/audit.py +0 -0
  88. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/decisions.py +0 -0
  89. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/enrollment.py +0 -0
  90. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/identity.py +0 -0
  91. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/jwks.py +0 -0
  92. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/manifests.py +0 -0
  93. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/scopes.py +0 -0
  94. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/api/v1/transaction.py +0 -0
  95. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/boundary/__init__.py +0 -0
  96. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/boundary/guarantee.py +0 -0
  97. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/cli/audit.py +0 -0
  98. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/cli/drift.py +0 -0
  99. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/cli/drift_render.py +0 -0
  100. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/cli/identity.py +0 -0
  101. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/cli/manifest.py +0 -0
  102. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/db.py +0 -0
  103. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/embedded/_transport.py +0 -0
  104. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/embedded/capabilities.py +0 -0
  105. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/embedded/export.py +0 -0
  106. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/embedded/store.py +0 -0
  107. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/agent.py +0 -0
  108. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/compiled_policy.py +0 -0
  109. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/imported_audit.py +0 -0
  110. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/manifest.py +0 -0
  111. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/reconciliation_report.py +0 -0
  112. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/sandbox_run.py +0 -0
  113. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/step_up_grant.py +0 -0
  114. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/transaction_token.py +0 -0
  115. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/trust_anchor.py +0 -0
  116. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/models/types.py +0 -0
  117. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/observability/__init__.py +0 -0
  118. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/observability/config.py +0 -0
  119. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/observability/context.py +0 -0
  120. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/observability/ids.py +0 -0
  121. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/observability/logs.py +0 -0
  122. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/observability/pep.py +0 -0
  123. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/observability/spans.py +0 -0
  124. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/observability/surface.py +0 -0
  125. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/observability/tracing.py +0 -0
  126. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/redis.py +0 -0
  127. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/repositories/__init__.py +0 -0
  128. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/repositories/agents.py +0 -0
  129. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/repositories/manifests.py +0 -0
  130. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/repositories/reconciliation_reports.py +0 -0
  131. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/repositories/transaction_tokens.py +0 -0
  132. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/repositories/trust_anchors.py +0 -0
  133. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/runtime.py +0 -0
  134. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/__init__.py +0 -0
  135. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/authorize.py +0 -0
  136. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/dag.py +0 -0
  137. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/edge_trace.py +0 -0
  138. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/identity.py +0 -0
  139. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/manifest.py +0 -0
  140. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/manifest_api.py +0 -0
  141. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/token.py +0 -0
  142. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/schemas/transaction.py +0 -0
  143. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sdk/__init__.py +0 -0
  144. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sdk/context.py +0 -0
  145. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sdk/drift.py +0 -0
  146. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sdk/errors.py +0 -0
  147. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sdk/identity.py +0 -0
  148. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sdk/planes.py +0 -0
  149. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sdk/provenance.py +0 -0
  150. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/__init__.py +0 -0
  151. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/anchors.py +0 -0
  152. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/audit_chain.py +0 -0
  153. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/audit_cursor.py +0 -0
  154. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/bundle_import.py +0 -0
  155. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/dag_compiler.py +0 -0
  156. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/decision_cache.py +0 -0
  157. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/decision_history.py +0 -0
  158. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/drift.py +0 -0
  159. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/edge_rules.py +0 -0
  160. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/edge_trace.py +0 -0
  161. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/enrollment.py +0 -0
  162. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/enrollment_rules.py +0 -0
  163. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/pdp.py +0 -0
  164. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/policy_loader.py +0 -0
  165. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/revocation.py +0 -0
  166. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/taint.py +0 -0
  167. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/tokens/__init__.py +0 -0
  168. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/tokens/act_chain.py +0 -0
  169. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/tokens/jwt_profile.py +0 -0
  170. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/tokens/keys.py +0 -0
  171. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/tokens/profile.py +0 -0
  172. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/tokens/replay.py +0 -0
  173. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/services/transactions.py +0 -0
  174. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sidecar/__init__.py +0 -0
  175. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sidecar/__main__.py +0 -0
  176. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sidecar/app.py +0 -0
  177. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sidecar/deny.py +0 -0
  178. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/sidecar/identity.py +0 -0
  179. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/verify/__init__.py +0 -0
  180. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/verify/admit.py +0 -0
  181. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/verify/anchors.py +0 -0
  182. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/verify/canonical.py +0 -0
  183. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/verify/grants.py +0 -0
  184. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/verify/identity.py +0 -0
  185. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/verify/replay.py +0 -0
  186. {authzai-0.2.1 → authzai-0.4.0}/agentic_auth/verify/transaction.py +0 -0
  187. {authzai-0.2.1 → authzai-0.4.0}/authzai.egg-info/dependency_links.txt +0 -0
  188. {authzai-0.2.1 → authzai-0.4.0}/authzai.egg-info/entry_points.txt +0 -0
  189. {authzai-0.2.1 → authzai-0.4.0}/authzai.egg-info/requires.txt +0 -0
  190. {authzai-0.2.1 → authzai-0.4.0}/authzai.egg-info/top_level.txt +0 -0
  191. {authzai-0.2.1 → authzai-0.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: authzai
3
- Version: 0.2.1
3
+ Version: 0.4.0
4
4
  Summary: Authorization for AI agents: per-hop narrowing authority, verifiable delegation chains, and an append-only audit log
5
5
  Author: Wong Xin Wei
6
6
  License-Expression: Apache-2.0
@@ -5,4 +5,4 @@ Imports nothing: ``import agentic_auth`` must work from the base install, which
5
5
  ``pyjwt[crypto]``.
6
6
  """
7
7
 
8
- __version__ = "0.2.1"
8
+ __version__ = "0.4.0"
@@ -60,6 +60,25 @@ async def require_enroller(authorization: Annotated[str | None, Header()] = None
60
60
  raise UnauthorizedError("invalid enroller bearer token")
61
61
 
62
62
 
63
+ async def require_consenter(authorization: Annotated[str | None, Header()] = None) -> None:
64
+ """Consent is called with the dedicated consent token or the admin token (feature 011).
65
+
66
+ A connector proxy or gateway starts sessions for the users it validates, so it needs to
67
+ call consent; it must not hold the admin token, which could register manifests (research
68
+ F2). An empty setting disables the consent token, never accepts an empty bearer.
69
+ """
70
+ if not authorization or not authorization.startswith("Bearer "):
71
+ raise UnauthorizedError("missing or malformed consenter bearer token")
72
+ presented = authorization.removeprefix("Bearer ").strip().encode()
73
+ settings = get_settings()
74
+ accepted = [t.encode() for t in (settings.consent_token, settings.admin_token) if t]
75
+ # Compare against every accepted token, not just until the first match, so timing does
76
+ # not reveal which one was presented.
77
+ matches = [hmac.compare_digest(presented, token) for token in accepted]
78
+ if not presented or not any(matches):
79
+ raise UnauthorizedError("invalid consenter bearer token")
80
+
81
+
63
82
  async def require_identity_reader(authorization: Annotated[str | None, Header()] = None) -> None:
64
83
  """Identity material and the revocation list are readable by verifiers and operators:
65
84
  the audit reader token or the admin token."""
@@ -105,8 +124,51 @@ async def presented_token(
105
124
 
106
125
  SessionDep = Annotated[AsyncSession, Depends(get_session)]
107
126
  PresentedTokenDep = Annotated[VerifiedToken, Depends(presented_token)]
127
+
128
+
129
+ async def require_consenting_human(
130
+ authorization: Annotated[str | None, Header()] = None,
131
+ ) -> str:
132
+ """Who may APPROVE a step-up widening: the human, not the agent (research.md R6).
133
+
134
+ The whole threat model assumes the agent may be under an attacker's influence. An
135
+ agent that could approve its own widening would turn ``SCOPE_NOT_CONSENTED`` from a
136
+ control into a formality — the injected instruction would simply answer the prompt it
137
+ triggered. So the session's own root grant is deliberately NOT sufficient here, even
138
+ though it is sufficient to *raise* the challenge.
139
+
140
+ Where the deployment has configured a human identity provider, this is an ID token
141
+ from it and the subject is its ``sub``. Where it has not, the admin bearer stands in
142
+ and the subject is recorded as ``admin`` — a deployment with no independent human
143
+ channel, which its documentation must say plainly rather than imply otherwise.
144
+
145
+ Returns the subject to record as the approver.
146
+ """
147
+ settings = get_settings()
148
+ if not authorization or not authorization.startswith("Bearer "):
149
+ raise UnauthorizedError("missing or malformed credential")
150
+ token = authorization.removeprefix("Bearer ").strip()
151
+
152
+ if settings.principal_idp_issuer:
153
+ from agentic_auth.services.principal import PrincipalBinder
154
+
155
+ try:
156
+ return await PrincipalBinder().verify_human(token)
157
+ except Exception as exc: # noqa: BLE001 - any failure here is a refusal
158
+ raise UnauthorizedError(f"human credential did not verify: {exc}") from exc
159
+
160
+ if hmac.compare_digest(token.encode(), settings.admin_token.encode()):
161
+ return "admin"
162
+ raise UnauthorizedError(
163
+ "step-up approval requires the consenting human's credential; the session's own "
164
+ "grant is not sufficient"
165
+ )
166
+
167
+
108
168
  AdminDep = Depends(require_admin)
109
169
  AuditReaderDep = Depends(require_audit_reader)
110
170
  EnrollerDep = Depends(require_enroller)
171
+ ConsenterDep = Depends(require_consenter)
111
172
  IdentityReaderDep = Depends(require_identity_reader)
173
+ ConsentingHumanDep = Annotated[str, Depends(require_consenting_human)]
112
174
  PaginationDep = Annotated[PaginationParams, Depends(pagination_params)]
@@ -20,7 +20,9 @@ from agentic_auth.services.enrollment import EnrollmentService
20
20
  from agentic_auth.services.manifest_service import ManifestService
21
21
  from agentic_auth.services.principal import PrincipalBinder
22
22
  from agentic_auth.services.revocation import RevocationService
23
+ from agentic_auth.services.sandbox import SandboxService
23
24
  from agentic_auth.services.sessions import SessionService
25
+ from agentic_auth.services.stepup import StepUpService
24
26
  from agentic_auth.services.tokens.exchange import TokenExchangeService
25
27
  from agentic_auth.services.tokens.jwt_profile import JwtTokenProfile
26
28
  from agentic_auth.services.tokens.profile import TokenProfile
@@ -100,6 +102,14 @@ def get_chain_query_service() -> ChainQueryService:
100
102
  return ChainQueryService()
101
103
 
102
104
 
105
+ def get_step_up_service() -> StepUpService:
106
+ return StepUpService()
107
+
108
+
109
+ def get_sandbox_service() -> SandboxService:
110
+ return SandboxService()
111
+
112
+
103
113
  ManifestServiceDep = Annotated[ManifestService, Depends(get_manifest_service)]
104
114
  RedisDep = Annotated[Redis, Depends(get_redis_dep)]
105
115
  TokenProfileDep = Annotated[TokenProfile, Depends(get_token_profile)]
@@ -111,3 +121,5 @@ AnchorCacheDep = Annotated[AnchorCache, Depends(get_anchor_cache)]
111
121
  EnrollmentServiceDep = Annotated[EnrollmentService, Depends(get_enrollment_service)]
112
122
  RevocationServiceDep = Annotated[RevocationService, Depends(get_revocation_service)]
113
123
  ChainQueryServiceDep = Annotated[ChainQueryService, Depends(get_chain_query_service)]
124
+ StepUpServiceDep = Annotated[StepUpService, Depends(get_step_up_service)]
125
+ SandboxServiceDep = Annotated[SandboxService, Depends(get_sandbox_service)]
@@ -0,0 +1,65 @@
1
+ """``/v1/agents/{agent_id}/clients`` — which IdP clients act as this agent (feature 011, M4).
2
+
3
+ Admin-only, and 404 unless ``client_mapping_enabled``: a deployment that has not opted in
4
+ should not discover the endpoints.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import uuid
10
+ from typing import Annotated
11
+
12
+ from fastapi import APIRouter, Query, Response, status
13
+
14
+ from agentic_auth.api.deps import AdminDep, PaginationDep, SessionDep
15
+ from agentic_auth.config import get_settings
16
+ from agentic_auth.errors import NotFoundError
17
+ from agentic_auth.schemas.agent_client import AgentClientCreate, AgentClientRead
18
+ from agentic_auth.schemas.common import Page, PageInfo
19
+ from agentic_auth.services.client_mapping import ClientMappingService
20
+
21
+ router = APIRouter(prefix="/v1/agents", tags=["client-mapping"], dependencies=[AdminDep])
22
+
23
+ ADMIN_IDENTITY = "admin"
24
+
25
+
26
+ def _require_enabled() -> None:
27
+ if not get_settings().client_mapping_enabled:
28
+ raise NotFoundError("client mapping is not enabled on this deployment")
29
+
30
+
31
+ @router.post(
32
+ "/{agent_id}/clients", response_model=AgentClientRead, status_code=status.HTTP_201_CREATED
33
+ )
34
+ async def map_client(
35
+ agent_id: uuid.UUID, body: AgentClientCreate, db: SessionDep
36
+ ) -> AgentClientRead:
37
+ _require_enabled()
38
+ row = await ClientMappingService().create(
39
+ db, agent_id, body.client_id, created_by=ADMIN_IDENTITY
40
+ )
41
+ return AgentClientRead.model_validate(row)
42
+
43
+
44
+ @router.get("/{agent_id}/clients", response_model=Page[AgentClientRead])
45
+ async def list_clients(
46
+ agent_id: uuid.UUID,
47
+ db: SessionDep,
48
+ pagination: PaginationDep,
49
+ include_removed: Annotated[bool, Query()] = False,
50
+ ) -> Page[AgentClientRead]:
51
+ _require_enabled()
52
+ rows, next_cursor = await ClientMappingService().list(
53
+ db, agent_id, pagination.limit, pagination.cursor, include_removed=include_removed
54
+ )
55
+ return Page(
56
+ data=[AgentClientRead.model_validate(r) for r in rows],
57
+ page=PageInfo(next_cursor=next_cursor, limit=pagination.limit),
58
+ )
59
+
60
+
61
+ @router.delete("/{agent_id}/clients/{client_id}", status_code=status.HTTP_204_NO_CONTENT)
62
+ async def unmap_client(agent_id: uuid.UUID, client_id: str, db: SessionDep) -> Response:
63
+ _require_enabled()
64
+ await ClientMappingService().remove(db, agent_id, client_id, removed_by=ADMIN_IDENTITY)
65
+ return Response(status_code=status.HTTP_204_NO_CONTENT)
@@ -34,8 +34,11 @@ from agentic_auth.observability import logs, surface
34
34
  from agentic_auth.schemas.authorize import AuthorizeDecision, AuthorizeRequest, DenyReason, Taint
35
35
  from agentic_auth.services import decision_cache, policy_loader
36
36
  from agentic_auth.services.audit import AuditService, RecordResult
37
+ from agentic_auth.services.guarantee import note_level
37
38
  from agentic_auth.services.metrics import get_metrics
38
39
  from agentic_auth.services.pdp import Decision, decide
40
+ from agentic_auth.services.sessions import PinnedSession
41
+ from agentic_auth.services.stepup import StepUpService, granted_classes
39
42
  from agentic_auth.services.taint import (
40
43
  Marked,
41
44
  TaintStore,
@@ -138,6 +141,7 @@ async def authorize(
138
141
  message="taint state could not be read for a protected target",
139
142
  ),
140
143
  policy_version=session.policy_version,
144
+ session=session,
141
145
  token=token,
142
146
  headers=request.headers,
143
147
  )
@@ -156,6 +160,24 @@ async def authorize(
156
160
  chain_agents.add(body.target.removeprefix("agent://")) # delegating TO a revoked agent
157
161
  revoked_on_chain = frozenset(revoked & chain_agents)
158
162
 
163
+ # -- step-up (Phase 5) -------------------------------------------------------
164
+ # The third decision input of this shape, after taint and the revoked set: loaded
165
+ # here, handed to the pure `decide()` as a parameter. A session is never mutated to
166
+ # record a widening (research.md R6).
167
+ consented = (
168
+ frozenset(session.consented_data_classes)
169
+ if session.consented_data_classes is not None
170
+ else None
171
+ )
172
+ step_up: frozenset[str] = frozenset()
173
+ if consented is not None and settings.step_up_enabled:
174
+ step_up = await granted_classes(
175
+ db,
176
+ redis,
177
+ body.session_id,
178
+ ttl_seconds=int((session.expires_at - _now()).total_seconds()),
179
+ )
180
+
159
181
  cache_key = decision_cache.key(
160
182
  body,
161
183
  policy_version=session.policy_version,
@@ -165,6 +187,8 @@ async def authorize(
165
187
  act_chain=token.act_chain,
166
188
  taint=taint,
167
189
  revoked=revoked_on_chain,
190
+ consented_data_classes=consented,
191
+ step_up=step_up,
168
192
  )
169
193
  decision = await decision_cache.get(redis, cache_key)
170
194
  if decision is None:
@@ -177,6 +201,8 @@ async def authorize(
177
201
  taint=taint,
178
202
  taint_enforced=settings.taint_enforcement_enabled,
179
203
  revoked=revoked_on_chain,
204
+ consented_data_classes=consented,
205
+ step_up=step_up,
180
206
  )
181
207
  await decision_cache.put(redis, cache_key, decision)
182
208
 
@@ -191,14 +217,54 @@ async def authorize(
191
217
  body,
192
218
  decision,
193
219
  policy_version=session.policy_version,
220
+ session=session,
194
221
  token=token,
195
222
  taint_source=taint_source,
196
223
  headers=request.headers,
197
224
  )
198
225
 
226
+ # -- the guarantee level: count it, and never let a degrade pass quietly --------
199
227
  get_metrics().decisions_by_guarantee.labels(
200
228
  level=body.guarantee.value, outcome=rendered.outcome
201
229
  ).inc()
230
+ await note_level(
231
+ db,
232
+ redis,
233
+ session_id=body.session_id,
234
+ level=body.guarantee,
235
+ caller=body.caller,
236
+ target=body.target,
237
+ policy_version=session.policy_version,
238
+ act_chain=token.act_chain,
239
+ ttl_seconds=int((session.expires_at - _now()).total_seconds()),
240
+ )
241
+
242
+ # -- offer a challenge, but only where one could actually be granted -------------
243
+ # A non-recoverable refusal never carries a challenge, so a client cannot put a
244
+ # prompt in front of a human for something that can never be approved (FR-024).
245
+ if (
246
+ settings.step_up_enabled
247
+ and rendered.recoverable
248
+ and rendered.action_id is not None
249
+ and consented is not None
250
+ ):
251
+ try:
252
+ rendered = rendered.model_copy(
253
+ update={
254
+ "step_up": await StepUpService().challenge(
255
+ db,
256
+ redis,
257
+ session_id=uuid.UUID(body.session_id),
258
+ blocked_action_id=rendered.action_id,
259
+ policy=policy,
260
+ )
261
+ }
262
+ )
263
+ except DomainError:
264
+ # The refusal stands on its own. A challenge that cannot be raised — the
265
+ # class is outside the manifest ceiling, say — must not turn a clean deny
266
+ # into an error the caller cannot act on.
267
+ logger.info("no step-up challenge offered for %s", rendered.reason)
202
268
 
203
269
  # -- mark: this call reaches for a source the caller does not trust ---------------
204
270
  # On an allow (or an observe-mode forwarded policy deny) the result will be consumed
@@ -316,6 +382,7 @@ async def _record(
316
382
  taint_source: str | None = None,
317
383
  step_up_ref: uuid.UUID | None = None,
318
384
  headers: Mapping[str, str] | None = None,
385
+ session: PinnedSession | None = None,
319
386
  ) -> tuple[AuthorizeDecision, RecordResult]:
320
387
  """Record, commit, then render from the result. Every decision is recorded — including
321
388
  the ones caused by an unreachable dependency, which are the ones an operator most needs
@@ -345,6 +412,9 @@ async def _record(
345
412
  # Phase 5. What the enforcement point said it is; recorded on every row.
346
413
  guarantee_level=body.guarantee.value,
347
414
  step_up_ref=step_up_ref,
415
+ # 0.4.0. None only when the session itself could not be read.
416
+ principal_source=session.principal_source if session is not None else None,
417
+ client_id=session.client_id if session is not None else None,
348
418
  )
349
419
 
350
420
  # A call leaves the host on an allow, and on an unenforced (observe-mode) deny. Either
@@ -4,11 +4,13 @@ from __future__ import annotations
4
4
 
5
5
  from fastapi import APIRouter, status
6
6
 
7
- from agentic_auth.api.deps import AdminDep, SessionDep
7
+ from agentic_auth.api.deps import ConsenterDep, SessionDep
8
8
  from agentic_auth.api.service_deps import RedisDep, SessionServiceDep
9
9
  from agentic_auth.schemas.consent import ConsentCreate, ConsentRead
10
10
 
11
- router = APIRouter(prefix="/v1", tags=["consent"], dependencies=[AdminDep])
11
+ # The consent token or admin (feature 011): what a connector proxy holds is enough to start a
12
+ # session for a user it validated, and nothing else.
13
+ router = APIRouter(prefix="/v1", tags=["consent"], dependencies=[ConsenterDep])
12
14
 
13
15
 
14
16
  @router.post("/consent", response_model=ConsentRead, status_code=status.HTTP_201_CREATED)
@@ -0,0 +1,181 @@
1
+ """``/v1/agents/{id}/sandbox`` and the proposal endpoints (FR-032..FR-042).
2
+
3
+ Admin-only throughout, and 404 unless ``sandbox_enabled``: a deployment that has not
4
+ adopted cold start should not advertise routes that run agents.
5
+
6
+ Nothing here can affect a decision. A proposal is a ``manifests`` row with status
7
+ ``proposed``, which the compiler never selects — so no policy is compiled for it, no
8
+ session can pin it, and no decision can resolve against it. That is asserted directly in
9
+ ``tests/unit/test_proposed_is_inert.py`` rather than left to emerge (research.md R12).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import uuid
15
+
16
+ from fastapi import APIRouter, Query, status
17
+ from sqlalchemy.ext.asyncio import AsyncSession
18
+
19
+ from agentic_auth.api.deps import AdminDep, SessionDep
20
+ from agentic_auth.api.service_deps import SandboxServiceDep
21
+ from agentic_auth.config import get_settings
22
+ from agentic_auth.errors import NotFoundError
23
+ from agentic_auth.models import Agent, SandboxRun
24
+ from agentic_auth.repositories import agents as agents_repo
25
+ from agentic_auth.repositories import sandbox_runs as runs_repo
26
+ from agentic_auth.schemas.sandbox import (
27
+ ObservedRead,
28
+ ProposedManifestRead,
29
+ RatifyRequest,
30
+ SandboxRunListItem,
31
+ SandboxRunPage,
32
+ SandboxRunRead,
33
+ SandboxStart,
34
+ )
35
+
36
+ router = APIRouter(prefix="/v1/agents", tags=["cold-start"], dependencies=[AdminDep])
37
+
38
+
39
+ def _require_enabled() -> None:
40
+ if not get_settings().sandbox_enabled:
41
+ raise NotFoundError("sandboxed observation is not enabled on this deployment")
42
+
43
+
44
+ async def _agent(db: AsyncSession, agent_id: uuid.UUID) -> Agent:
45
+ agent = await agents_repo.get_by_id(db, agent_id)
46
+ if agent is None:
47
+ raise NotFoundError(f"unknown agent {agent_id}")
48
+ return agent
49
+
50
+
51
+ def _read(run: SandboxRun) -> SandboxRunRead:
52
+ observed = None
53
+ proposal = (run.trace or {}).get("x-proposal") if isinstance(run.trace, dict) else None
54
+ if proposal:
55
+ observed = ObservedRead(**proposal.get("observed", {}))
56
+ return SandboxRunRead(
57
+ id=run.id,
58
+ agent_id=run.agent_id,
59
+ status=run.status,
60
+ scope=run.scope,
61
+ started_at=run.started_at,
62
+ deadline_at=run.deadline_at,
63
+ ended_at=run.ended_at,
64
+ recorder_errors=run.recorder_errors,
65
+ observed=observed,
66
+ )
67
+
68
+
69
+ @router.post(
70
+ "/{agent_id}/sandbox", response_model=SandboxRunRead, status_code=status.HTTP_201_CREATED
71
+ )
72
+ async def start_run(
73
+ agent_id: uuid.UUID,
74
+ body: SandboxStart,
75
+ db: SessionDep,
76
+ sandbox: SandboxServiceDep,
77
+ ) -> SandboxRunRead:
78
+ """Begin observing. Every call the agent attempts is allowed and recorded, and every
79
+ tool it can reach is a mock with nothing real behind it (FR-032)."""
80
+ _require_enabled()
81
+ await _agent(db, agent_id)
82
+ run = await sandbox.start(
83
+ db, agent_id=agent_id, scope=body.scope, deadline_seconds=body.deadline_seconds
84
+ )
85
+ return _read(run)
86
+
87
+
88
+ @router.get("/{agent_id}/sandbox", response_model=SandboxRunPage)
89
+ async def list_runs(
90
+ agent_id: uuid.UUID,
91
+ db: SessionDep,
92
+ limit: int = Query(default=50, ge=1, le=200),
93
+ ) -> SandboxRunPage:
94
+ _require_enabled()
95
+ await _agent(db, agent_id)
96
+ rows = await runs_repo.list_for_agent(db, agent_id, limit=limit)
97
+ return SandboxRunPage(
98
+ data=[SandboxRunListItem.model_validate(r) for r in rows],
99
+ next_cursor=rows[-1].started_at.isoformat() if len(rows) == limit else None,
100
+ )
101
+
102
+
103
+ @router.get("/{agent_id}/sandbox/{run_id}", response_model=SandboxRunRead)
104
+ async def read_run(
105
+ agent_id: uuid.UUID,
106
+ run_id: uuid.UUID,
107
+ db: SessionDep,
108
+ sandbox: SandboxServiceDep,
109
+ ) -> SandboxRunRead:
110
+ _require_enabled()
111
+ run = await runs_repo.get(db, run_id)
112
+ if run is None or run.agent_id != agent_id:
113
+ raise NotFoundError(f"unknown run {run_id}")
114
+ # The deadline is applied on read rather than by a sweeper: a run only matters when
115
+ # someone asks, and a second place to get the deadline wrong is a second bug.
116
+ return _read(await sandbox.expire_if_due(db, run))
117
+
118
+
119
+ @router.get("/{agent_id}/proposed-manifest", response_model=ProposedManifestRead)
120
+ async def read_proposal(
121
+ agent_id: uuid.UUID,
122
+ db: SessionDep,
123
+ sandbox: SandboxServiceDep,
124
+ run_id: uuid.UUID | None = None,
125
+ ) -> ProposedManifestRead:
126
+ """The manifest proposed from a run — inert until ratified."""
127
+ _require_enabled()
128
+ agent = await _agent(db, agent_id)
129
+
130
+ run = (
131
+ await runs_repo.get(db, run_id)
132
+ if run_id is not None
133
+ else await runs_repo.latest_completed(db, agent_id)
134
+ )
135
+ if run is None or run.agent_id != agent_id:
136
+ raise NotFoundError("no completed sandbox run for this agent")
137
+
138
+ row = await sandbox.propose(db, run, agent_name=agent.name)
139
+ return ProposedManifestRead(
140
+ manifest_id=row.id,
141
+ agent_id=agent_id,
142
+ run_id=run.id,
143
+ status="proposed",
144
+ doc=row.doc,
145
+ covers_no_behaviour=bool(
146
+ (row.doc.get("x-proposal") or {}).get("covers_no_behaviour", False)
147
+ ),
148
+ )
149
+
150
+
151
+ @router.post("/{agent_id}/proposed-manifest/ratify", status_code=status.HTTP_201_CREATED)
152
+ async def ratify_proposal(
153
+ agent_id: uuid.UUID,
154
+ body: RatifyRequest,
155
+ db: SessionDep,
156
+ sandbox: SandboxServiceDep,
157
+ ) -> dict:
158
+ """The human act that makes a proposal real (FR-037).
159
+
160
+ For an agent with no prior manifest this pins version 1, immutable from here
161
+ (FR-038). Reconciliation then runs against it exactly as it would for a hand-written
162
+ manifest, so a ratified manifest that fails reconciliation does not enrol the agent
163
+ (FR-042).
164
+ """
165
+ _require_enabled()
166
+ await _agent(db, agent_id)
167
+ row = await sandbox.ratify(
168
+ db,
169
+ run_id=body.run_id,
170
+ agent_id=agent_id,
171
+ approved_by="admin",
172
+ document=body.doc,
173
+ )
174
+ return {
175
+ "manifest_id": str(row.id),
176
+ "agent_id": str(agent_id),
177
+ "version": row.version,
178
+ "status": row.status,
179
+ "ratified_by": row.ratified_by,
180
+ "ratified_at": row.ratified_at.isoformat() if row.ratified_at else None,
181
+ }
@@ -0,0 +1,86 @@
1
+ """``/v1/consent/step-up`` — a recoverable refusal becomes a question (FR-022..FR-031).
2
+
3
+ Two routes, with deliberately different authentication:
4
+
5
+ - **Raising** a challenge takes the session's own grant or an admin bearer. Asking is
6
+ harmless; it grants nothing.
7
+ - **Answering** one takes the consenting human's credential. An agent that could approve
8
+ its own widening would turn ``SCOPE_NOT_CONSENTED`` into a formality, and the whole
9
+ threat model assumes the agent may be under an attacker's influence (research.md R6).
10
+
11
+ Both answer 404 unless ``step_up_enabled``, so a deployment that has not adopted step-up
12
+ does not advertise an endpoint it will refuse everything from.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from fastapi import APIRouter, status
18
+
19
+ from agentic_auth.api.deps import AdminDep, ConsentingHumanDep, SessionDep
20
+ from agentic_auth.api.service_deps import RedisDep, SessionServiceDep, StepUpServiceDep
21
+ from agentic_auth.config import get_settings
22
+ from agentic_auth.errors import NotFoundError
23
+ from agentic_auth.schemas.authorize import StepUpChallenge
24
+ from agentic_auth.schemas.stepup import StepUpComplete, StepUpGrantRead, StepUpRequest
25
+ from agentic_auth.services import policy_loader
26
+
27
+ router = APIRouter(prefix="/v1/consent", tags=["step-up"])
28
+
29
+
30
+ def _require_enabled() -> None:
31
+ if not get_settings().step_up_enabled:
32
+ raise NotFoundError("step-up consent is not enabled on this deployment")
33
+
34
+
35
+ @router.post(
36
+ "/step-up",
37
+ response_model=StepUpChallenge,
38
+ status_code=status.HTTP_201_CREATED,
39
+ dependencies=[AdminDep],
40
+ )
41
+ async def raise_challenge(
42
+ body: StepUpRequest,
43
+ db: SessionDep,
44
+ redis: RedisDep,
45
+ sessions: SessionServiceDep,
46
+ stepup: StepUpServiceDep,
47
+ ) -> StepUpChallenge:
48
+ """Ask the human whether to widen this session by the data class that was refused.
49
+
50
+ The session's pinned policy is loaded here so the ceiling can be checked before a
51
+ human is ever asked: a widening that could not be granted should fail now, not after
52
+ someone approves it.
53
+ """
54
+ _require_enabled()
55
+ session = await sessions.get(db, redis, str(body.session_id))
56
+ policy = await policy_loader.load(db, redis, session.scope, session.policy_version)
57
+ return await stepup.challenge(
58
+ db,
59
+ redis,
60
+ session_id=body.session_id,
61
+ blocked_action_id=body.blocked_action_id,
62
+ policy=policy,
63
+ )
64
+
65
+
66
+ @router.post("/step-up/complete", response_model=StepUpGrantRead)
67
+ async def complete_challenge(
68
+ body: StepUpComplete,
69
+ approver: ConsentingHumanDep,
70
+ db: SessionDep,
71
+ redis: RedisDep,
72
+ sessions: SessionServiceDep,
73
+ stepup: StepUpServiceDep,
74
+ ) -> StepUpGrantRead:
75
+ """Record the human's answer. On an approval the chain may resume from the blocked
76
+ hop; on a decline the original refusal stands."""
77
+ _require_enabled()
78
+ settings = get_settings()
79
+ return await stepup.complete(
80
+ db,
81
+ redis,
82
+ challenge_id=body.challenge_id,
83
+ approved=body.approved,
84
+ approved_by=approver,
85
+ session_ttl_seconds=settings.session_ttl_seconds,
86
+ )
@@ -131,6 +131,8 @@ async def exchange_token(
131
131
  privileged=denied.decision.privileged,
132
132
  policy_version=denied.policy_version,
133
133
  token=denied.token,
134
+ principal_source=denied.principal_source,
135
+ client_id=denied.client_id,
134
136
  )
135
137
  if denied.decision.reason is not None:
136
138
  get_metrics().denials.labels(reason=denied.decision.reason.value).inc()
@@ -0,0 +1,33 @@
1
+ """``/.well-known/oauth-authorization-server`` — the control plane's RFC 8414 metadata
2
+ (feature 011, M3).
3
+
4
+ Unauthenticated and cacheable, like the JWKS. 404 unless ``as_metadata_enabled``.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Any
10
+
11
+ from fastapi import APIRouter
12
+ from fastapi.responses import JSONResponse
13
+
14
+ from agentic_auth.api.deps import SessionDep
15
+ from agentic_auth.config import get_settings
16
+ from agentic_auth.errors import NotFoundError
17
+ from agentic_auth.oauth.metadata import authorization_server_metadata
18
+ from agentic_auth.services.catalog_service import pinned_data_classes
19
+
20
+ router = APIRouter(tags=["ops"])
21
+
22
+
23
+ @router.get("/.well-known/oauth-authorization-server")
24
+ async def get_authorization_server_metadata(db: SessionDep) -> Any:
25
+ settings = get_settings()
26
+ if not settings.as_metadata_enabled:
27
+ raise NotFoundError("authorization server metadata is not enabled on this deployment")
28
+ document = authorization_server_metadata(
29
+ settings.issuer,
30
+ scopes=await pinned_data_classes(db),
31
+ transaction_tokens=settings.transaction_tokens_enabled,
32
+ )
33
+ return JSONResponse(document, headers={"cache-control": "public, max-age=300"})