Repository navigation
feat: agent auth batch for 2.0 - #272
Merged
Merged
Conversation
Template shows a beforeAuthorize adapter that denies by default on error or timeout.
Idempotent on email, so the quickstart no longer inserts into theauth_users by hand.
Returns 401 for a missing or invalid agent token and 403 with the denial reason when the scope is not granted.
Provider, adapter, test and runtime dependency counts now come from scripts/stats.mjs.
Delegate, MCP call, out-of-scope denial, revoke and audit log in one runnable example.
Drops the hand-written theauth_users insert now that user.create ships.
Same email with a different id now throws a typed UserError, and unique violations are recovered without onConflictDoNothing.
Not wired yet. Defaults to a 2000ms timeout and deny on timeout or error.
Moves authorize and authorizeByToken out of theauth-core into src/authorize/pipeline.ts, and replaces reason-text matching with DECISION_CODES. Breaking: classification changes.
beforeAuthorize now runs after agent resolution with the delegation chain, covers authorizeByToken and policy.evaluate, times out and denies on error by default, and blocked calls write a chained audit row with a decision_code column. Breaking: see docs/upgrading-to-2.mdx.
authorize() checked status only, so an expired agent still passed. Now denied with agent_expired and an audit row. Breaking for agents that relied on the old behavior.
Deny by default on error or timeout, deny-overrides when composing several guards.
Resource and action strings are inferred from declared permissions. vitest config now runs the .test-d.ts type tests.
Adds an unhashed recorded_at_ms column (migration 0003) so same-second rows keep write order, and writes a chained delegation.revoke row per revoked link.
explain() reports the matched grant, delegation link and decision code with no side effects. The simulator now applies delegated constraints like authorize().
Action and resource are paired like authorize.
A delegation link now counts only if its delegator agent is active and unexpired. One filter feeds authorize, lineage, the MCP check and the simulator. Breaking: chains that passed before can now fail.
Moves the agent, audit and human-auth facades and plugin wiring into modules. theauth.delegation.revoke now accepts { revokedBy } so revoke audit rows record who revoked.
agentMayUse and loadGrants now use the shared filter, and a delegator with its own direct permissions keeps onward links its own authority covers. Breaking: vault access that succeeded before can now be refused.
Real output from a run against current core.
Removes codes that are never emitted, adds the real delegation, user, token and OAuth codes, and drops the reserved wording on hook_timeout and hook_error.
Provider and adapter counts match docs/stats.json, delegation.create and createAgent samples use the real API, client README rewritten, llms files regenerated.
Comments and test titles use colons or commas. Test assertions that matched dashed text changed with them.
Move-only: scim, sso, openapi, passkey, oidc-provider, organization, presets, stripe, rebac, device-auth, federation and a2a types. Original paths still export the same names.
createTheAuthHandler, listRoutes, requireAgent and a Node bridge. Serves every advertised MCP route including new /mcp/revoke and /mcp/jwks, adds POST /explain, records the socket peer address out of band for client IP, and returns 403 for a foreign userId on audit export. Adds the ./http and ./testing subpath exports.
explain() returns the closest near-miss grants on a denial. @glinr/theauth/testing and theauth policy test run table-driven policy suites.
Adds theauth_schema_migrations with checksums, baseline stamping for existing databases, SchemaOutdatedError for skipMigrations, per-dialect generated SQL, a dialect suite for Postgres and MySQL (opt-in via env), and theauth db status|up|sql. schema.ts and migrations.ts split into modules. Audit hash inputs unchanged.
Each adapter is thin glue around createTheAuthHandler and exports requireScope driven by decision codes. Removes the five copied dispatch.ts files and the deprecated aliases. Breaking: option names unified, status codes unified (revoked token returns 401).
Signed POST of the hook context to a vendor endpoint, strict response schema, fails closed on network error, redirect, non-2xx or malformed body. verifyGuardRequest for vendors, theauth-conformance guard, and a reference server.
init detects the framework, seeds an owner with user.create and a demo agent on a SQLite file, never overwrites without --force. doctor adds schema, version and proxy checks and a --live mode. Templates use better-sqlite3 and generated secrets.
…tutorial to the nav
… with the approved reason
Contributor
|
Thanks for your first pull request. CI will run shortly. If the change touches package source, please add a changeset with |
| } | ||
|
|
||
| }; | ||
| router.use(handle); |
| app.use(express.json()); | ||
| app.use( | ||
| "/api/auth/theauth", | ||
| buildTheAuthRouter(await makeTheAuth(), stubMcp, { allowUnauthenticated: true, ...extra }), |
| const warn = vi.spyOn(console, "warn").mockImplementation(() => undefined); | ||
| try { | ||
| const app = express(); | ||
| app.use("/api/theauth", theAuthMiddleware({ theauth, allowUnauthenticated: true })); |
| app.use(express.json()); | ||
| app.use( | ||
| "/api/theauth", | ||
| theAuthMiddleware({ theauth, authenticate: async () => ({ id: "admin" }) }), |
…e paths without a regex
…ess session tamper test
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Summary
Type of change
Related issues
Test plan
Which commands did you run to verify this change?
Public API impact
If breaking: describe the migration path.
Database migration
packages/core/migrations/Framework adapter impact
If adapters are affected, confirm you tested against the relevant one.
Documentation updated
docs/Em-dash check
Checklist
pnpm test)pnpm typecheck)pnpm lint)anytypes introducedconsole.logleft in production codepnpm changeset)