feat(agent-auth): approvalMethodHandlers for the Server-Defined Approval Profile (§10.10.3) - #38
Open
envisean wants to merge 1 commit into
Conversation
…methods
§7.4 notes that custom approval methods "are defined, if at all, by
extension profiles such as the Server-Defined Approval Profile
(§10.10.3)". approvalMethods/resolveApprovalMethod already let a
server name and select a custom method, but buildApprovalInfo had no
way to actually build one -- any resolved method other than "ciba"
fell through to the device_authorization branch unconditionally,
silently mislabeling the stored ApprovalRequest.
Adds approvalMethodHandlers: a registry of method name -> handler on
AgentAuthOptions, consulted in buildApprovalInfo before the built-in
branches. A resolved method with a matching handler is built by that
handler and becomes the approval object in the API response; behavior
for ciba/device_authorization and for any method without a registered
handler is unchanged. Per §7's approval-object schema, method,
expires_in, and interval are required on every method's response,
including server-defined ones -- the handler is responsible for
including them; the type itself stays Record<string, unknown> rather
than enforcing this, matching how the two built-in methods are already
handled elsewhere in this file (plain object literals, no shared
enforced base type).
Widens ApprovalRequest.method past its two-value literal union
(string & {}) to keep autocomplete for the two built-ins while
allowing registered custom names -- the underlying column was always
a plain string, this is a type-only change.
Adds packages/agent-auth/src/__tests__/server-defined-approval-methods.test.ts:
a registered handler wins over the built-ins, device_authorization is
unaffected when no handler is registered, a resolved method with no
matching handler still falls back to device_authorization, and the
same behavior holds through request-capability on an already-active
agent, not just at registration.
This branch has not been deployed
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
§7.4 notes that custom approval methods are "defined, if at all, by extension profiles such as the Server-Defined Approval Profile (§10.10.3)".
approvalMethods/resolveApprovalMethodalready let a server name and select a custom method, butbuildApprovalInfohad no way to actually build one — any resolved method other than"ciba"fell through to thedevice_authorizationbranch unconditionally, silently mislabeling the storedApprovalRequest.This adds
approvalMethodHandlers: a registry of method name → handler onAgentAuthOptions, consulted inbuildApprovalInfobefore the built-in branches. A resolved method with a matching handler is built by that handler and becomes theapprovalobject in the API response.ciba/device_authorizationbehavior is unchanged, and any resolved method without a registered handler still falls back todevice_authorizationexactly as before.method/expires_in/intervalare required on every method's response, including server-defined ones — noted in the JSDoc as the handler's responsibility. Left the type itself asRecord<string, unknown>rather than enforcing this, matching how the two built-in methods are already handled elsewhere in this file (plain object literals, no shared enforced base type).ApprovalRequest.methodpast its two-value literal union (string & {}) to keep autocomplete for the two built-ins while allowing registered custom names — the underlying column was always a plain string, so this is a type-only change.Note for maintainers
While researching this against the actual spec (not just this file's existing comments), I noticed the pre-existing
§9/§9.5citations onapprovalMethods/resolveApprovalMethodin this same file appear to predate a renumbering — the current v1.0-draft has Approval Methods at §7, with the extension profile at §10.10.3, not §9.§2.4(lifetime clocks) checks out correctly against the current draft, so this doesn't look like a wholesale renumbering, just this pocket of citations. Didn't touch those pre-existing lines since I didn't introduce them and it's a separate changeset — flagging in case it's worth its own pass.Test plan
packages/agent-auth/src/__tests__/server-defined-approval-methods.test.ts: a registered handler wins over the built-ins,device_authorizationis unaffected when no handler is registered, a resolved method with no matching handler still falls back todevice_authorization, and the same behavior holds throughrequest-capabilityon an already-active agent, not just at registration.tsc --noEmitcleantsupbuild clean (ESM + DTS)oxfmt --checkclean