Dynamically setting the session domain?

Does anyone know a way to dynamically change the session_domain option
of ActionController::CgiRequest? I want to have a login section on an
index page (www.example.com) that takes a subdomain, username,
password, authenticates, then redirects to
http://#{subdomain}.mysite.com.

I need to set the session_domain option (to the subdomain) dynamically
so the cookie can be read when the user arrives after the redirect. I
know I could do
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(
:session_domain => ‘example.com’) if I wanted to share sessions across
domains, but I do not want to do this as I want to allow users to be
logged on to multiple subdomains at the same time.

Any ideas?

Thanks,
Zack

I just realized that 37Signal’s Backpack does exactly what I described
below. Any ideas on how this is done?

Thanks,
Zack