Django, Angular, DRF: Authentication to Django backend vs. API

2024/11/13 9:34:33

I'm building an app with a Django backend, Angular frontend, and a REST API using Django REST Framework for Angular to consume. When I was still working out backend stuff with a vanilla frontend, I used the provided Django authentication to handle user auth- but now that I'm creating a REST based app, I'm not sure how to approach authentication.

Since all user data will be either retrieved or submitted via the API, should API authentication be enough? If so, do I need to remove the existing Django authentication middleware?

Right now, when I try to hit API endpoints on an early version of the app, I'm directed to what looks like the normal Django login form. If I enter a valid username and password, it doesn't work- just prompts to login again. Would removing the basic Django authentication prevent this? I want to be prompted to login, however I'm not sure how to handle that with these technologies.

The package django-rest-auth seems useful, and the same group makes an Angular module- but the docs don't go much past installation and the provided endpoints. Ultimately, I think the core of this question is: how do I entirely switch authentication away from what's provided by Django to something like django-rest-auth or one of the other 3rd party packages recommended by DRF?

edit: I made this comment below, but I realized that I need to figure out how combined auth will work. I'm not building a single page app, so individual basic pages will be served from Django, but each page will hit various API endpoints to retrieve the data it needs. Is there a way to have something like django-rest-auth handle all authentication?

Answer

To anyone that stumbles onto this question, I couldn't figure out how to make the hybrid approach work. Having Django serve pages that each contained API calls seemed OK, but I never saw any requests made to the API- I believe due to some other security issues. I'm sure it's possible, but I decided to go for the single page app implementation after all to make things simpler.

https://en.xdnf.cn/q/72499.html

Related Q&A

Django view testing

Im trying to figure out if there is a quick way to test my django view functions form either the python or django shell. How would I go about instantiating and passing in faux HTTPrequest object?

Remove non-ASCII characters from string columns in pandas

I have panda dataframe with multiple columns which mixed with values and unwanted characters. columnA columnB columnC ColumnD \x00A\X00B NULL \x00C\x00D 123 \x00E\X00F…

Open source Twitter clone (in Ruby/Python) [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.We don’t allow questi…

What is the best way to connect to a Sybase database from Python?

I am trying to retrieve data in a Sybase data base from Python and I was wondering which would be the best way to do it. I found this module but may be you have some other suggestions: http://python-sy…

How to get N random integer numbers whose sum is equal to M

I want to make a list of N random INTEGER numbers whose sum is equal to M number.I have used numpy and dirichlet function in Python, but this generate double random number array, I would like to genera…

Why sqlalchemy declarative base object has no attribute query?

I created declarative table. from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, String from sqlalchemy.dialects.postgresql import UUID import uuidBase = declarative_…

Django ModelForm not saving data

Ive tried solutions from the following posts: Saving data from ModelForm : Didnt workModelForm data not saving django : Didnt work. Im trying to save data from a ModelForm into the model. models.py:cla…

When is it appropriate to use sample_weights in keras?

According to this question, I learnt that class_weight in keras is applying a weighted loss during training, and sample_weight is doing something sample-wise if I dont have equal confidence in all the …

Django South - turning a null=True field into a null=False field

My question is, what is the best practice for turning a null=True field into a null=False field using Django South. Specifically, Im working with a ForeignKey.

Apostrophes are printing out as \x80\x99

import requests from bs4 import BeautifulSoup import resource_url = requests.get(http://www.nytimes.com/pages/business/index.html) div_classes = {class :[ledeStory , story]} title_tags = [h2,h3,h4,h5,h…