Integrate django and RoR (rubies on rails)

I have a site created by someone else with ruby-on-rails, and now I am creating a django application.

I need my users to log in with their django-built login page and view my django pages (still easy to do), but I also need to add sidebar links to this RoR application (and from there they can back to my application).

Users do not need to know that they are β€œleaving” the django application β€” their website is for them β€” this RoR application looks and feels the same for them.

A. How to do it?
B. They are part of the django app, so django will be managing sessions and all user content. How can I skip sessions in a RoR application? Should I use iframe?
C. What do django's RoR url links look like?

Thanks guys!

+6
source share
2 answers

The best practice here would be to see how ad networks exchange data for several properties. One commonly used technique is pixel tracking. For example, in your Django application, paste:

<img src="http://myrailsapp/mysession_creator" /> 

Verify that the rails application is responding to this address with a session. This will set the session cookie in the rails domain.

Now to the level of security, and it depends on what level of security you need. You can pass information, for example:

 <img src="http://myrailsapp/mysession_creator?user=myUserName" /> 

Obviously, this is incredibly safe, but it depends on your application. More secure method:

 <img src="http://myrailsapp/mysession_creator?t=<MD5HashTokenHere>" /> 

Then the Rails application will have a mechanism for checking this token on the server side of the Django application (either through the state of the database or the server call of the application). More work, but safer.

Another method, if your applications share the root domain, you can use a secure cookie in the root domain to transfer information between applications. For example, https://django.myapp.com sets the cookie myapp.com and https://rails.myapp.com knows how to search for the "username" cookie. Requires an SSL certificate of wildcard in the root domain.

Another option is to pass the token or login data with each link to the Rails application and have a before_filter that recognizes the transfer and establishes a session in the same way.

+2
source

I'm not sure if this will work, but we did it before using 2 rails applications.

Ensure that the session keys in Rails and in the django application match.

In Rails, it will look something like this:

 ActionController::Base.session = { :key => '_my_session_key', :secret => '_my_session_secret' } 

In Django, a quick google led me to this:

https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY

I think that when everything is the same, both applications will use the same session.

0
source

Source: https://habr.com/ru/post/895417/


All Articles