0

So I am using a third party Authentication (Firebase Auth)(Facebook && Google) with my Django Application.

I did set up some rest endpoints that need authentication to post some content.

I will very well like to use the Django Rest Framework Token Authentication. However, this requires that I have to pass a username & password in other to get the token.

Since I am using Firebase(Facebook and Google), users are not asked to set any password. Here is my CustomUser model.

class CustomUser(AbstractUser):
    email = models.EmailField(unique=True)
    uid = models.CharField(max_length=191, null=False)
    first_name = models.CharField(max_length=20, default="", blank=True)
    last_name = models.CharField(max_length=20, default="", blank=True)
    address = models.CharField(max_length=150, default="", blank=True)

Is there any workaround or ideas on this?

1 Answer 1

1

It is hard to tell without a hint about your user model, but Django Rest Framework Token doesn't require a password. You can create a token by providing user only (which doesn't have to be django's auth user model).

from rest_framework.authtoken.models import Token

Token.objects.create(user=user)

To use Django's user model without a password, you can use user.set_unusable_password() right after creating the user object.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I added some code for the CustomUser, please do take a look.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.