webauthn::json_contract (public)
webauthn::json_contract docstring query_specs
Defined in packages/webauthn/tcl/webauthn-procs.tcl
Helper for JSON endpoints with page-contract-like parameter validation. This procedure validates and normalizes request parameters according to 'query_specs#, using OpenACS page-contract filters via 'ad_page_contract_filter_invoke'. Parsed values are exported into the caller’s scope (via 'uplevel') so the endpoint can use them as normal Tcl variables. On validation failure, this procedure does not generate HTML complaint output. Instead, it returns a JSON error (HTTP 400) using [$auth_obj return_err], taking the first complaint message from 'ad_complaints_get_list', and aborts the script via 'ad_script_abort'.
- Parameters:
- docstring (required)
- Human-readable endpoint documentation (currently unused by this helper; included to mirror 'ad_page_contract' call style and for future diagnostics/logging).
- query_specs (required)
- List of parameter specifications, like in 'ad_page_contract'
- Returns:
- The configured WebAuthn auth object (currently '::webauthn::passkey')
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: set auth_obj ::webauthn::passkey if {![nsf::is object $auth_obj]} { ns_return 500 application/json {{"error":"passkey auth object not configured"}} ad_script_abort return } if {[llength $query_specs] > 0} { #ns_log notice "DEBUG: specs <[string trim $query_specs]>" # "ns_getform" triggers auto-parsing, which sets also the # cached JSON value set formData [ns_getform] #ns_log notice "DEBUG: have JSON body [info exists ::_ns_json_body]" set provided [expr {[info exists ::_ns_json_body] ? [ns_parsequery [ns_conn query]] : $formData}] #ns_log notice "DEBUG: query <[ns_conn query]>" #ns_log notice "DEBUG: provided [ns_set format $provided]" foreach p $query_specs { #ns_log notice "DEBUG: processing query spec <$p>" unset -nocomplain default if {[llength $p] == 2} { lassign $p spec default } else { lassign $p spec } #ns_log notice "DEBUG: processing query spec <$p> info exists default [info exists default]" lassign [split $spec :] name filters #ns_log notice "DEBUG: ns_set find $provided $name -> [ns_set find $provided $name]" if {[ns_set find $provided $name] != -1} { set value [ns_set get $provided $name] foreach filter [split $filters ,] { set r 1 if {$filter eq "trim"} { set value [string trim $value] } elseif {$filter eq "notnull"} { } elseif {[regexp {^(.+)[\(](.+)[\)]} $filter . filter_name filter_args]} { set r [ad_page_contract_filter_invoke $filter_name $name value [list [split $filter_args |]]] } else { set r [ad_page_contract_filter_invoke $filter $name value] } ns_log notice DEBUG ad_page_contract_filter_invoke $filter $name value -> $r // $value if {$r == 0} { $auth_obj return_err -status 400 "invalid-argument" "Query parameter: [lindex [ad_complaints_get_list] 0]" ad_script_abort } } } else { set value $default } if {$value eq "" && "notnull" in [split $filters ,]} { ad_complain -key $formal_name:notnull [_ acs-tcl.lt_You_must_specify_some] $auth_obj return_err -status 400 "invalid-argument" "Query parameter: [lindex [ad_complaints_get_list] 0]" ad_script_abort } ns_log notice DEBUG FINAL set $name $value uplevel [list set $name $value] } } return $auth_objXQL Not present: Generic, PostgreSQL, Oracle