Forum: Ruby on Rails Sharing sessions between subdomains?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
softwareengineer 99 (Guest)
on 2006-02-08 13:40
(Received via mailing list)
Hello,

   I know how to share sessions between subdomains  in PHP. Can anyone
please guide me as to how I can share sessions using  Ruby? Where can I
set the value of domain for which the cookie is set?

    I would like for a user to login on the home page and then go to
blog.home.com and not have to login again.

    Any guidance/pointers are appreciated.

    Thanks'
    Frank
sach (Guest)
on 2006-02-08 14:46
softwareengineer 99 wrote:
> Hello,
>
>    I know how to share sessions between subdomains  in PHP. Can anyone
> please guide me as to how I can share sessions using  Ruby? Where can I
> set the value of domain for which the cookie is set?
>
>     I would like for a user to login on the home page and then go to
> blog.home.com and not have to login again.
>
>     Any guidance/pointers are appreciated.
>
>     Thanks'
>     Frank

Isn't that just a matter of how you have your cookie set?

Instead of setting the domain of the cookie to 'blog.home.com' just set
it to '.home.com' and then that cookie should be valid for any host
under the 'home.com' domain.
Alex Y. (Guest)
on 2006-02-08 14:50
(Received via mailing list)
sach wrote:
>>     Any guidance/pointers are appreciated.
>>
>>     Thanks'
>>     Frank
>
> Isn't that just a matter of how you have your cookie set?
>
> Instead of setting the domain of the cookie to 'blog.home.com' just set
> it to '.home.com' and then that cookie should be valid for any host
> under the 'home.com' domain.

I believe the question was 'how'...  The answer is here:

http://api.rubyonrails.com/classes/ActionControlle...
softwareengineer 99 (Guest)
on 2006-02-08 15:14
(Received via mailing list)
Thanks Alex for your reply.

  Should the cookies be set in application.rb? I tried using
  cookies[:domain]='domain.com' but got an "undefined variable" error?

  Where should this setting for cookies  be set if I want it to be
applied on a application wide level?

  I also tried my controller file but to no avail?

  Then I placed the cookie settings in environment.rb. I don't get an
error but the session isn't recognized on the subdomain?

  I appreciate your assistance very much.

  Thanks
  Frank


Alex Y. <removed_email_address@domain.invalid> wrote:

I believe the question was 'how'...  The answer is here:

http://api.rubyonrails.com/classes/ActionControlle...

--
Alex
Dee Z. (Guest)
on 2006-02-08 16:27
(Received via mailing list)
You need to set the session domain in your production.rb

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(
:session_domain => '.suprglu.com')

For develpment&&testing you should change test.rb, and development.rb:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(
:session_domain => '.localhost.com')

then configure your /etc/hosts file to map localhost.com,
something.localhost.com to 127.0.0.1. You now have a subdomained
development setup at your disposal!

For functional tests you would place this into test/test_helper.rb

module ActionController
  class TestRequest
    def with_subdomain(subdomain=nil)
      the_host_name = "localhost.com"
      the_host_name = "#{subdomain}.localhost.com" if subdomain
      self.host = the_host_name
      self.env['SERVER_NAME'] = the_host_name
      self.env['HTTP_HOST'] = the_host_name
    end
  end
end

then for test suites needing subdomained requests you can add this to
your
setup:

@request.with_subdomain('primalgrasp')

Zsombor
softwareengineer 99 (Guest)
on 2006-02-08 16:30
(Received via mailing list)
Thanks for your reply.
  I am setting the cookie to .home.com in my login function but when I
go to blog.home.com, the session isn't being recognized.

  Can anyone please guide me on where is the optimal place to set the
cookie?
  Thanks
  Frank

sach <removed_email_address@domain.invalid> wrote:  softwareengineer 99 wrote:
>
>     Thanks'
>     Frank

Isn't that just a matter of how you have your cookie set?

Instead of setting the domain of the cookie to 'blog.home.com' just set
it to '.home.com' and then that cookie should be valid for any host
under the 'home.com' domain.

--
Posted via http://www.ruby-forum.com/.
softwareengineer 99 (Guest)
on 2006-02-08 16:36
(Received via mailing list)
Hi Zsombor,

  Thank you very much for your reply.
  I will test it out right now.

  Thanks again.
  Frank

Dee Z. <removed_email_address@domain.invalid> wrote:  You need to set the 
session
domain in your production.rb

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(
:session_domain => '.suprglu.com')

For develpment&&testing you should change test.rb, and development.rb:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(
:session_domain => '.localhost.com')

then configure your /etc/hosts file to map localhost.com,
something.localhost.com to 127.0.0.1. You now have a subdomained
development setup at your disposal!

For functional tests you would place this into test/test_helper.rb

module ActionController
  class TestRequest
    def with_subdomain(subdomain=nil)
      the_host_name = "localhost.com"
      the_host_name = "#{subdomain}.localhost.com" if subdomain
      self.host = the_host_name
      self.env['SERVER_NAME'] = the_host_name
      self.env['HTTP_HOST'] = the_host_name
    end
  end
end

then for test suites needing subdomained requests you can add this to
your
setup:

@request.with_subdomain('primalgrasp')

Zsombor
--
Company  - http://primalgrasp.com
Thoughts - http://deezsombor.blogspot.com
softwareengineer 99 (Guest)
on 2006-02-08 17:06
(Received via mailing list)
Hello Zsombor,

  >> You need to set the session domain in your production.rb

  I placed the following code in production.rb, development.rb and
test.rb

  ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain
=> '.domain.com')

  and the functional tests snippet in test/test_helper.rb.

  Then I restarted the server and logged in at domain.com. Then I went
to  blog.domain.com and it's not recognizing session and asking me again
for password.

  Did I miss something?

  I highly appreciate your assistance.

  Frank
  P.S. I just added your blog to my reading list ;)
softwareengineer 99 (Guest)
on 2006-02-08 17:09
(Received via mailing list)
I spoke too soon as after clearing the cookies it works!
  Zsombor, thank you so much for your time and assistance. I owe you one
;)

  Frank

softwareengineer 99 <removed_email_address@domain.invalid> wrote:  Hello
Zsombor,

  >> You need to set the session domain in your production.rb

  I placed the following code in production.rb, development.rb and
test.rb

  ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain
=> '.domain.com')

  and the functional tests snippet in test/test_helper.rb.

  Then I restarted the server and logged in at domain.com. Then I went
to  blog.domain.com and it's not recognizing session and asking me again
for password.

  Did I miss something?

  I highly appreciate your assistance.

  Frank
  P.S. I just added your blog to my reading list ;)



---------------------------------
Brings words and photos together (easily) with
   PhotoMail  - it's free and works with Yahoo!
Mail._______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
Ezra Z. (Guest)
on 2006-02-08 22:11
(Received via mailing list)
On Feb 8, 2006, at 3:39 AM, softwareengineer 99 wrote:

>
> Thanks'
> Frank


Frank-

	I think this is what you need. This line goes in config/environments/
production.rb or development.rb:


ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update
( :session_domain => '.example.com')


	Note the . before example.com , that is what makes the sessions work
between subdomains.

Cheers-

-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid
Wiktor -. (Guest)
on 2006-06-15 03:07
> ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update
> ( :session_domain => '.example.com')

What if I don't know session_domain at this stage. Can I set it up in
controller? How?
This topic is locked and can not be replied to.