Forum Discussion
karthik_sriniva
Nimbostratus
Apr 07, 2005Setting HTTP COOkie
Hi,
I am trying to set a HTTP Cookie from AUTH_SUCCESS event and I get the following error
[command is not valid in current event context (AUTH_SUCCESS)] [HTTP::username]
If the authentication was successful, is there way to set a cookie.
Thanks,
Karthik
- rapmaster_c_127Historic F5 AccountYou could always set a variable whose value you'd later check in the HTTP_RESPONSE event... If you paste the overall rule you have in mind (e.g. is the cookie inserted as a serverside Set-Cookie, or do you want to insert it on the client side? What profiles do you have in the chain? What are you trying to accomplish?) we can work through it.
- karthik_sriniva
Nimbostratus
when CLIENT_ACCEPTED { set tmm_auth_radius_sid [AUTH::start pam default_radius] } when HTTP_REQUEST { set username {encrypt {[HTTP::username]}} if { [HTTP::cookie exists "XYZ"] } { use pool gtwLogin HTTP::release } if { ![HTTP::cookie exists "XYZ"] } { log "in auth block" AUTH::username_credential $tmm_auth_radius_sid [HTTP::username] AUTH::password_credential $tmm_auth_radius_sid [HTTP::password] AUTH::authenticate $tmm_auth_radius_sid if {$tmm_auth_radius_sid eq [AUTH::last_event_session_id]} { log "abt to set auth hdr " set newauth [b64encode [format "%s:%s" [HTTP::username] "xxxx"]] HTTP::header insert Authorization "Basic $newauth" } HTTP::collect } } when AUTH_SUCCESS { if {$tmm_auth_radius_sid eq [AUTH::last_event_session_id]} { log "called release after auth success" [HTTP::cookie value "XYZ2" username] HTTP::release } } when AUTH_FAILURE { if {$tmm_auth_radius_sid eq [AUTH::last_event_session_id]} { HTTP::respond 401 } } when AUTH_WANTCREDENTIAL { if {$tmm_auth_radius_sid eq [AUTH::last_event_session_id]} { HTTP::respond 401 } } when AUTH_ERROR { if {$tmm_auth_radius_sid eq [AUTH::last_event_session_id]} { HTTP::respond 401 } } when HTTP_RESPONSE { }
- Tao_Liu_90341Historic F5 AccountI assume you trying to use a cookie to bypass authentication. In this manner, cookie should be set in HTTP_RESPONSE, so client will get it, otherwise HTTP server just would throw it away.
when CLIENT_ACCEPTED { set authinsck 0 set forceauth 1 set ckname BIGXAUTH set ckpass 1xxx5678 set ckvalue [IP::client_addr] set ckdomain .y.z set asid [AUTH::start pam default_radius] } when HTTP_REQUEST { if {[HTTP::cookie exists $ckname]} { HTTP::cookie decrypt $ckname $ckpass 128 if {[HTTP::cookie value $ckname] eq $ckvalue} { set forceauth 0 } HTTP::cookie remove $ckname } if {$forceauth eq 1} { AUTH::username_credential $asid [HTTP::username] AUTH::password_credential $asid [HTTP::password] AUTH::authenticate $asid HTTP::collect } } when HTTP_RESPONSE { if {$authinsck eq 1} { HTTP::cookie insert name $ckname value $ckvalue path / domain $ckdomain HTTP::cookie secure $ckname enable HTTP::cookie encrypt $ckname $ckpass 128 } } when AUTH_SUCCESS { if {$asid eq [AUTH::last_event_session_id]} { set authinsck 1 HTTP::release } } when AUTH_FAILURE { if {$asid eq [AUTH::last_event_session_id]} { HTTP::respond 401 "WWW-Authenticate" "Basic realm=\"\"" } } when AUTH_WANTCREDENTIAL { if {$asid eq [AUTH::last_event_session_id]} { HTTP::respond 401 "WWW-Authenticate" "Basic realm=\"\"" } } when AUTH_ERROR { if {$asid eq [AUTH::last_event_session_id]} { HTTP::respond 401 } }
- karthik_sriniva
Nimbostratus
Thanks for your reply. But I have one problem with your code, this block of code is not working - Tao_Liu_90341Historic F5 AccountI don't know why, it is likely your brower did not send the cookie. Try to remove line
- unRuleY_95363Historic F5 AccountDid you update the domain to match the domain associated with your VIP?
- karthik_sriniva
Nimbostratus
Thanks Gentlemen for all your help.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects