xo::ProtocolHandler instproc set_user_id (public)

 <instance of xo::ProtocolHandler[i]> set_user_id

Defined in packages/xotcl-core/tcl/50-protocol-handler-procs.tcl

Set user_id based on authentication header

Partial Call Graph (max 5 caller/called nodes):
%3 ad_conn ad_conn (public) auth::authenticate auth::authenticate (public) auth::get_register_authority auth::get_register_authority (public) http_auth::basic_authentication_decode http_auth::basic_authentication_decode (public) xo::ProtocolHandler instproc set_user_id xo::ProtocolHandler instproc set_user_id xo::ProtocolHandler instproc set_user_id->ad_conn xo::ProtocolHandler instproc set_user_id->auth::authenticate xo::ProtocolHandler instproc set_user_id->auth::get_register_authority xo::ProtocolHandler instproc set_user_id->http_auth::basic_authentication_decode

Testcases:
No testcase defined.
Source code:
:log "[ns_conn method] request comes with headers [ns_set array [ns_conn headers]]"
set ah [ns_set iget [ns_conn headers] Authorization]
if {$ah ne ""} {
  #
  # Get credentials from a basic authentication string like
  # "Basic 29234k3j49a".
  #
  set credentials [http_auth::basic_authentication_decode $ah]
  set auth [auth::authenticate  -username [dict get $credentials user]  -authority_id [::auth::get_register_authority]  -password [dict get $credentials password]]

  if {[dict get $auth auth_status] ne "ok"} {
    set auth [auth::authenticate  -email [dict get $credentials user]  -password [dict get $credentials password]]

    if {[dict get $auth auth_status] ne "ok"} {
      :log "auth status [dict get $auth auth_status]"
      set :user_id 0
      throw {AUTH UNAUTHORIZED {unauthorized}} [dict get $auth auth_status]
    }
  }
  :log "auth_check user_id='[dict get $auth user_id]'"
  ad_conn -set user_id [dict get $auth user_id]

} else {
  # no authenticate header, anonymous visitor
  ad_conn -set user_id 0
  ad_conn -set untrusted_user_id 0
}
set :user_id [ad_conn user_id]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: