# Using same user credentials across multiple connected apps

**URL:** <https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894>\
**Category:** rubyonrails-talk\
**Created:** [April 24, 2009, 7:28am UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894 "2009-04-24T07:28:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_Dave](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Sahil\_Dave](https://discuss.rubyonrails.org/u/Sahil_Dave)\
**Post date:** [April 24, 2009, 7:28am UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/1 "2009-04-24T07:28:00Z")

</div>

Hi,

I have a requirement in my project, where i need to create multiple apps that need to be integrated. One of the apps would be used for authentication that uses Authlogic. I need a single sign-on solution, so that once a user is logged in he remains logged-in for all the other apps as well.

Now, the user\_session being created in the auth app, is not accessible in the other apps. Is there a way i can share a user\_session between multiple apps.

Here is some code i am using in the other apps: [http://pastie.org/455710](http://pastie.org/455710)

If anyone has faced a similar issue, please point me to some possible solutions.

Regards.

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [April 24, 2009, 7:40am UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/2 "2009-04-24T07:40:54Z")

</div>

> Hi,
> 
> I have a requirement in my project, where i need to create multiple apps that need to be integrated. One of the apps would be used for authentication that uses Authlogic. I need a single sign-on solution, so that once a user is logged in he remains logged-in for all the other apps as well.

you can use something like [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/rubycas-server/)

Fred

---

<div class="post-metadata">

**Author:** ![Sahil\_Dave](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Sahil\_Dave](https://discuss.rubyonrails.org/u/Sahil_Dave)\
**Post date:** [April 24, 2009, 9:57am UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/3 "2009-04-24T09:57:41Z")

</div>

thanks for the link to this nice gem. but can i share the same session\_id across multiple sub-domains on the same server, without using the above gem?

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [April 24, 2009, 10:05am UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/4 "2009-04-24T10:05:04Z")

</div>

you can. If my memory is correct, the :session\_domain option allows you to set the domain the session cookie is saved under. (this does of course assume that contents of the session will be meaningful to all the apps).

Fred

---

<div class="post-metadata">

**Author:** ![Sahil\_Dave](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Sahil\_Dave](https://discuss.rubyonrails.org/u/Sahil_Dave)\
**Post date:** [April 27, 2009, 7:28am UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/5 "2009-04-27T07:28:40Z")

</div>

ok, i have the set the 2 apps to use the same session\_domain, like this ActionController::CgiRequest::DEFAULT\_SESSION\_OPTIONS.update (:session\_domain =\> '.localhost.com')

i am also using the same secret key across both apps, as cookies are found using that key. But still this does not work! Maybe its because i am using authlogic and it has its own way of finding the user in the current\_session.

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [April 27, 2009, 7:37am UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/6 "2009-04-27T07:37:16Z")

</div>

Check that the cookie that contains the session is actually being set under the right domain (and in development you'll need to fakeup some domains eg app1.mydomain.local, app2.mydomain.local).

Fred

---

<div class="post-metadata">

**Author:** ![Sahil\_Dave](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Sahil\_Dave](https://discuss.rubyonrails.org/u/Sahil_Dave)\
**Post date:** [April 27, 2009, 9:03am UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/7 "2009-04-27T09:03:45Z")

</div>

i checked the cookies on my browser one is set under localhost.com and other under blog.localhost.com, i have set these in /etc/hosts. Also, :session\_domain =\> ".localhost.com"

But there is one difference between the 2. localhost.com has 2 cookies(one of which is named user\_credentials), while blog.localhost.com has just 1 cookie, whose name is same as the 1st cookie under localhost.com

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [April 27, 2009, 11:08am UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/8 "2009-04-27T11:08:53Z")

</div>

Maybe authlogic sets it own cookies. I'd delve into authlogic and see how it decides which domain to use for its cookies.

Fred

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [January 25, 2010, 7:13pm UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/9 "2010-01-25T19:13:11Z")

</div>

Hi Sahil,

Were you able to figure out the solution to this problem? I've seen the same behavior but have not delved into the internals of authlogic.

Ravi.

Frederick Cheung wrote:

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [July 12, 2010, 12:42pm UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/10 "2010-07-12T12:42:43Z")

</div>

Hi, I've described SSO solution with authlogin in my blog ([http://bit.ly/ajGym2](http://bit.ly/ajGym2)). This post is in Russian, but you can use Google Translate or ask me 🙂

Sahil Dave wrote:

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [July 12, 2010, 12:44pm UTC](https://discuss.rubyonrails.org/t/using-same-user-credentials-across-multiple-connected-apps/41894/11 "2010-07-12T12:44:38Z")

</div>

Ooh, i've forgot to tell that there are one problem - this solution does not working in Opera browser, because Opera does not support session sharing for subdomains ☹

Alexey Poimtsev wrote:
