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):
_ _ (public) ad_complain ad_complain (public) ad_complaints_get_list ad_complaints_get_list (public) ad_page_contract_filter_invoke ad_page_contract_filter_invoke (public) ad_script_abort ad_script_abort (public) webauthn::json_contract webauthn::json_contract webauthn::json_contract->_ webauthn::json_contract->ad_complain webauthn::json_contract->ad_complaints_get_list webauthn::json_contract->ad_page_contract_filter_invoke webauthn::json_contract->ad_script_abort

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} {
            set provided [ns_getform]
            foreach p $query_specs {
                unset -nocomplain default
                if {[llength $p] == 2} {
                    lassign $p spec default
                } else {
                    lassign $p spec
                }
                lassign [split $spec :] name filters
                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_obj
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: