Rails User management system to django user management system for REST API

25 views
Skip to first unread message

Asif Saifuddin

unread,
Nov 12, 2017, 1:54:53 AM11/12/17
to Django users
Hi,

I have and existing live project running on rails. I have to expose the API's using django for now. I have generated models and edited them to create django model and mapping and exposed some API locally.

I have one issue which is confusing my mind.

That is how would I use the existing users/authors etc from DB to django User management system?

Any suggestion would be appreciated.

Regards,

Asif


Andréas Kühne

unread,
Nov 12, 2017, 3:56:25 AM11/12/17
to django...@googlegroups.com
Hi,

I really doubt this is a good idea. But if you want to user the same database for both applications, you will need to map up the database user model in django.

You can find information about that on the following pages:

As I said though, I don't think this is a good idea, because the user objects in rails and django probably have different properties that they need / don't need.

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2b085937-4b66-480d-86e0-01cd018d1f8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Schneider

unread,
Nov 12, 2017, 10:17:36 PM11/12/17
to django...@googlegroups.com
You would likely have to recreate the users on the Django side based on a data dump from Rails. That part should be easy to do. If Rails does not use a compatible password hash algorithm, then you probably can't copy the password haha over. If that's the case, generate random passwords (or set them as unusable, which I think Django supports) and force password resets.

If you want to authenticate against the existing Rails database, you'll need to write a custom Django authentication back-end that knows how to retrieve the Rails credentials and authenticate the user. 

This could include an API call from Django to Rails to log in to the Rails application. Once the user successfully logs in to the Rails app, I would recommend creating the user locally in Django automatically (using the password that just worked against Rails). If you have the built-in auth system listed before your custom back-end, then the next time the user logs in, they'll authenticate directly against Django, effectively migrating the user transparently, and Django does not need to talk to Rails again for that user. Note that the user will now unknowingly have two sets of credentials, and changing the password on one system will not sync with the other.

You can also potentially use Django to dip in to the Rails database, but that would be much more messy.

SSO is also an option, although there's a fair amount of infrastructure needed for that.

The API call is probably the easiest way to move the users over. Users who don't migrate themselves by logging in can later be manually migrated by creating users and forcing password resets, like I mentioned.

In any event, you'll probably be writing a custom authentication back-end.



-James
Reply all
Reply to author
Forward
0 new messages