cookies - Rails 4 multitencancy with subdomain login management -


Scenario: Multi-tenant rail app which uses subdomain and is planning Problem: I want the user to Must be able to log in to my domain. Com can then be forwarded as a logged-in user to its own subdomain at 1.mydomain.com address . Now they can only log in their own subdomain.

I am a relative tracks novice and I can not find a simple solution (though it seems that there should be one). Ideally I want to share a cookie to mydomain.com and subdomain1.mydomain.com, but my skills are not to write custom middleware, obviously because it is a majority, so I can not share a session in all subdomains. For some days it is stranded on and curious if there is a simple solution (such as the config.session_store domain setting) that I'm not remember before seeing OAuth or other more complex solutions, any help would be appreciated!

Edit: Of course I only found it after posting. . Config.session_store will try the domain: with the recommendation of all the filters first and if it does not work, then any details will post, at least one good idea sounds like.

Edit: The solution that works with my particular sub-rule setup:

  class ApplicationController & lt; ActionController :: Base before_action: check_subdomain def check_subdomain until request.subdomain == "" or request.subdomain == session [: subdomain] redirect_to request.protocol + request.domain end-end end session_store.rb mine :: application.config. Session_store: cookie_store, key: '_my_session' ,: domain = & gt; : All ,: tld_length = & gt; 2  

Actually I am setting a subdomain in the session with the session [subdomain] and use that session to use the current user session. Otherwise, when the domain is set: All in the session breaks the scope if the user is not authorized, then they are redirected to the public home page via the request. Protocol (http: // or https: //) + request.domain redirects simple! Now users can move between the base domain and their subdomain in the same session.

cookies

I guess there is a problem with the tracking of your session cookie, we had a similar problem with our subdomain-driven apps, which is left out of the cookie every time you switch between the two

We found the solution here:

  # Config / initializers / session_store.rb Your_App :: application.config.session_store: cookie_store, key: '_your_app_session', domain :: all, tld_length: 2  

move The tld_length argument - allows you to define how many "levels" of the domain can be adjusted; IE If you are using subdomains, you should set


forwarding

to reflect tld_length

I'm not sure whether there is a problem with your forwarding ; I'll give you some ideas.

When you log in to a "subdomain", unless you have implemented a true multi-tenancy of railways (where each user is stored in a separate database), Should be able to allow login, and then they should redirect to the subdomain without any problem

You should consider anything subdomain constraint if you _url Path assistants, then only the population will be:

  "your name", path_urble (subdomain: "subdomain_1")% & Gt; The reason for this is that the  _path  assistant is relative to the base URL, and the resulting  subdomain  option can not be populated optional. By the way, the  _url  path assistant number in the entirety of the URL allows you to define subdomains as needed 

-

If you send requests and requests Amp; The user wants to continue to stay signed-in, you will need to ensure that you are able to continue authentication in the sub-domain. IE If you have single-sign form on the "Home" page, then you want to make sure that you can continue authentication in the subdomain


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -