Tuesday, November 22, 2016

Re: Django authorisation within PostgreSQL

What you want is not entirely clear. Do you want to authenticate against your PostgreSQL users instead of the django.contrib.auth users? If yes, you need to customize your authentication [1]. One solution would be to write a custom authentication backend, but you might also be able to use RemoteUserBackend [2] together with Apache and mod_auth_pgsql.

Or do you want to import PostgreSQL users and groups into the django.contrib.auth tables and use those from now on? This should be possible with some SQL (INSERT INTO auth_user (id, first_name, last_name, email, ...) SELECT ... FROM [wherever PostgreSQL keeps its users]), but the "password" field might be tricky to transfer.

I know these don't answer all your questions, but you need to explain a bit more.

Regards,

Antonis

[1] https://docs.djangoproject.com/en/1.10/topics/auth/customizing/
[2] https://docs.djangoproject.com/en/1.10/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend

Antonis Christofides  http://djangodeployment.com
On 2016-11-22 14:52, Danny Remmerswaal wrote:
Hey guys,

I'm working on a Django project which has a native PostgreSQL database, filled with schemes that contain both read-only and normal tables and with it's own user- and group roles.

After manually changing the search_path variable, I have managed to import my current models by running the migrate.inspectdb command and improved the generated models by sorting, changing primary keys etc.
Django's automatic admin interface added new tables which can contain users, but ideally that's not what I want for my project. I'd rather have my current login- and group roles defined in PostgreSQL implemented in Django, because there are some already defined restrictions and triggers implemented in my PostgreSQL database that use these user- and group roles. 


Is there any convenient way to import the already defined user- and group roles in PostgreSQL so they work with Django? 
As a start I'd like a login page that based on supplied credentials grants access to my database with defined users that are part of the group "analyse" (I.E cevoo).
I've included an image that shows my database schemes and user/groups. Hopefully you guys can help me out!

With kind regards,

Danny
--
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-users@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/ddbd5a11-91fa-4411-b084-306b59b39e95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment