auth::token::redeem (public)
auth::token::redeem -purpose purpose -token token -callback callback
Defined in packages/acs-authentication/tcl/token-procs.tcl
Redeem a token for the expected purpose. The callback is a trusted command prefix. It receives the user ID and stored context as its final arguments and runs in the token transaction. It must enforce the operation's authorization rules. A normal return consumes the token. An error rolls back the operation and leaves the token available to retry until expiry. External side effects belong after commit.
- Switches:
- -purpose (required)
- -token (required)
- -callback (required)
- Returns:
- A dictionary with status invalid, or status redeemed and the callback result.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: if {![llength $callback]} { error "Action token redemption requires a callback" } set invalid {status invalid} if {![regexp {^[0-9a-f]{64}$} $token]} { return $invalid } set digest [ns_crypto::md string -digest sha256 -encoding hex $token] set user_id [db_string find_token_account { select user_id from auth_action_tokens where token_digest = :digest and purpose = :purpose } -default ""] if {$user_id eq ""} { return $invalid } set result $invalid db_transaction { if {[auth::token::lock_account $user_id]} { set now [clock seconds] if {[db_0or1row find_redeemable_token { select token_context from auth_action_tokens where user_id = :user_id and purpose = :purpose and token_digest = :digest and expires_at > :now }]} { set value [{*}$callback $user_id $token_context] db_dml consume_token { delete from auth_action_tokens where user_id = :user_id and purpose = :purpose and token_digest = :digest } set result [dict create status redeemed result $value] } } } return $resultXQL Not present: Generic, PostgreSQL, Oracle