Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django rest-auth get user profile

I´m a little bit lost... I´m trying to develop an ionic app witch needs to be authenticated versus Django web application.

I installed Django-Rest-Framework and Django-Rest-Auth. I´m able to login, getin the user with the token, but how can I retrieve more User data?

url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^rest-token-auth/$',obtain_auth_token),

With Django-rest-auth in host.com/rest-auth/user/ url I only have this data:

HTTP 200 OK
Content-Type: application/json
Vary: Accept
Allow: GET, PUT, HEAD, OPTIONS, PATCH

{
    "username": "ikerib",
    "email": "[email protected]",
    "first_name": null,
    "last_name": null
}

But I need more! like id, user_photo, city...

I tried configuring a user serializer like this:

from rest_framework import serializers
from gamer.models import GamerUser

class GameUserSerializer(serializers.ModelSerializer):
    class Meta:
        model = GamerUser
        fields = ('id', 'fullname', 'get_photo', 'karma')

and this view:

@csrf_exempt
def gameuser_detail(request, pk):
    try:
        gameuser = GameUser.objects.get(pk=pk)
    except GameUser.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = GameUserSerializer(gameuser)
        return JSONResponse(serializer.data)

but I´m unable to get user data because I don´t know the user id..

any help or clue???

thanks in advance

like image 403
Kioko Kiaza Avatar asked Nov 01 '15 16:11

Kioko Kiaza


People also ask

What is the rest Auth API in Django?

Django REST Authconveniently provides API endpoints for user registration, login/logout, password change/reset, social auth, and more. Make sure to update the INSTALLED APPSlist in “settings.py”: INSTALLED_APPS=[...'rest_framework','rest_framework.authtoken','rest_auth','django.contrib.sites','allauth','allauth.account','rest_auth.registration',...

How do I use remote user authentication in Django?

RemoteUserAuthentication This authentication scheme allows you to delegate authentication to your web server, which sets the REMOTE_USERenvironment variable. To use it, you must have django.contrib.auth.backends.RemoteUserBackend(or a subclass) in your AUTHENTICATION_BACKENDSsetting.

What is a custom user in Django?

Custom users using Django REST framework | Kraken Systems Ltd. The built-in Django User model follows the pattern consisted of username, email and password. In this tutorial you will learn to RESTfully simplify it to just email and password.

What is OAuth in Django?

Django REST framework OAuth. The Django REST framework OAuth package provides both OAuth1 and OAuth2 support for REST framework. This package was previously included directly in REST framework but is now supported and maintained as a third party package.


1 Answers

You can simply add your custom serializer to your app settings like this:

REST_AUTH_SERIALIZERS = {
    'USER_DETAILS_SERIALIZER': 'path.to.custom.GameUserSerializer',
}

http://django-rest-auth.readthedocs.org/en/latest/configuration.html

like image 126
mariodev Avatar answered Sep 23 '22 08:09

mariodev