Django authentication for multiple apps - python

I want to make two apps in my Django project - one for web pages (browser) and one for api calls (mobile app). Both apps should use same users for authentication.
So how should I implement it? I want to make one more app for users, but is it the right way to make app with just one model and without any other logic?

You can use Custom User by extending the existing User model in Django. You can refer Extending user Model for more details.
Hope this helps.

Related

How two Django applications use same database for authentication

previously we implemented one django application call it as "x" and it have own database and it have django default authentication system, now we need to create another related django application call it as "y", but y application did n't have database settings for y application authentication we should use x applications database and existing users in x application, so is it possible to implement like this?, if possible give the way how can we use same database for two separated django applications for authentication system.
Sorry for my english
Thanks for spending time for my query
So, to achieve this. In your second application, add User model in the models.py and remember to keep managed=False in the User model's Meta class.
Inside your settings.py have the same DATABASES configuration as of your first application.
By doing this, you can achieve the User model related functionality with ease in your new application.

Django with DRF and OAUTH2.0

I'm trying development a system with Django and Django Rest Framework, since i started i found out two problem, first for authentication second for permissions, i want use OAuth2.0 to make it possible, and django-oauth-toolkit.
Now, i wanna know how i authenticate a user and give the right for his, if he is admin or normal user?

Overriding Django admin vs creating new templates/views

I am a total noob with Django, I come from the PHP world and I am used to doing things differently.
I'm building an app and I want to change the way the backend looks, I want to use Bootstrap 4 and add a lot of custom stuff e.g. permission based admin views, and I was wondering what is the best practice, or how do more experienced django devs go about it?
Do they override all the django.contrib.admin templates, or do they build custom templates and login/register next to it, and use the django.contrib.admin only for the superuser?
What is the django way?
Django admin is intended for administration purposes. For all intents and purposes it is a direct interface to your database. While I have seen some people building customer facing interfaces using admin, this is most definitely not the way to make a general Django web application.
You should define views for your models. You can use built-in APIs to login and authenticate users. You should most likely restrict access to admin to internal users only.
As for templates, the modern way of doing things is to dynamically fetch data using an API and do all the UI logic in Javascript. Django can be used very well to provide an API to a frontend. Look into Django REST Framework. The basic idea is to write serializers for your models and have view functions serve the serialized data to the front end.
You could go the old school way and render your pages using templates of course. In that case your views would render templates using data provided by your models.
Yes. The admin pages is actually for administering the webpage. For user login and registration you create the templates. However, if you want your backend to look different then you can tweak the template for the admin page, admin login page as well. And you can also have permission based admin views. It's okay to over ride the defaults as long as you know what you're doing. Hope that helped.

Separate Django Auth Database...Different Table Name?

I'm in the process of setting up a custom blog app using Django, with Mezzanine as the blog, which will be communicating with the auth system on my other Django app to handle all user authentication.
So far, I have set up an AuthRouter exactly like the example described here: Multi DB Setup in Django
However, my other Django app has a custom AUTH_USER_MODEL defined in its settings file.
As a result, when attempting to login to the blog, it is looking for a table with a different name from auth_user. I'm wondering if there is a way to specify the auth user table?
Thanks for any advice!
You need to have the code for your custom User model (or similar) in the blog project also. The you can set the proper table name with db_table (if auto generated is different). Then you will set AUTH_USER_MODEL in your second project to point to your custom model defined in the same project. You also need to modify your router to work with this custom user model.

Django user activated apps on site

What would be the best approach to implement functionality that can be added or removed depending on the users preferences? What i am trying to do is to have a standard set of apps/functionality for all registered users and allow users to add any extra apps they would like from a list of the ones provided. As stated in the question this is django specific question. However, any information on how this is achieved in any other language will be very helpful. I'm sure there is a lot of information out there since it's very similar to adding apps on facebook.
Don't get confused between django apps (used to split up projects into parts with similar purpose) and a facebook app which is more like a program/widget.
Are you trying to create a platform that allows developers to create apps, or will you be creating all the apps?
Django has a built in permissions model that works with the built in django authentication. https://docs.djangoproject.com/en/dev/topics/auth/#methods, you can create a new permission for each app. Assign that permission to users that are allowed to interact with your app. And check for the permission before allowing a user to use the app.
There are also apps that allow for object level permissions.

Categories

Resources