auth::token::issue (public)
auth::token::issue -purpose purpose -user_id user_id -ttl ttl \
[ -context context ]Defined in packages/acs-authentication/tcl/token-procs.tcl
Issue a token, replacing the outstanding token for this account and purpose. Deliver the returned token only through the channel authorized by the caller. Use an application-defined purpose and keep context free of credentials.
- Switches:
- -purpose (required)
- -user_id (required)
- -ttl (required)
- Lifetime in seconds.
- -context (optional)
- Optional state for the redemption callback (up to 4000 bytes).
- Returns:
- The raw token, which is stored only as a digest.
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: if {![regexp {^[a-z][a-z0-9_]{0,63}$} $purpose]} { error "Invalid action token purpose" } if {![string is integer -strict $ttl] || $ttl <= 0} { error "Action token lifetime must be a positive integer" } if {[string bytelength $context] > 4000} { error "Action token context exceeds 4000 bytes" } set token [ns_crypto::randombytes -encoding hex 32] set digest [ns_crypto::md string -digest sha256 -encoding hex $token] db_transaction { if {![auth::token::lock_account $user_id]} { error "Cannot issue an action token for a missing account" } set expires_at [expr {[clock seconds] + $ttl}] db_dml replace_token { delete from auth_action_tokens where user_id = :user_id and purpose = :purpose } db_dml insert_token { insert into auth_action_tokens (user_id, purpose, token_digest, expires_at, token_context) values (:user_id, :purpose, :digest, :expires_at, :context) } } return $tokenXQL Not present: Generic, PostgreSQL, Oracle