Hello everyone,
I have developed an application with the backend built in Django and the frontend built in Vue.
Currently, we are retrieving a token on the frontend, which we then send in the headers to authenticate the user.
Now, we would like to apply the same approach to access the Django admin panel.
To achieve this, I have created the following endpoint and view:
URL:
path('admin/login/', CustomAuthView.as_view()),
View:
class CustomAuthView(views.View):
def get(self, request):
if user_obj := self.user_has_permission(request):
login(request, user_obj)
return redirect('/admin/')
return HttpResponseForbidden("You do not have permission to access this page")
Essentially, this view takes the token from the Authorization header, extracts the user from the token, and checks if the user is a superuser. If they are, it redirects them to the admin panel.
When testing this using Postman, I am able to retrieve the HTML content of the admin panel. However, I would like to access the normal admin panel, would it be possible?
Thanks!
1 post - 1 participant