garyburgmann / drf-firebase-auth

Firebase backend to receive a user idToken and authenticate via Django REST Framework 'authentication.BaseAuthentication'. Optionally, a new local user can be created in the process.
MIT License
127 stars 61 forks source link

You should let to decide an unique username in def get_or_create_local_user() #25

Closed Provoo closed 3 years ago

Provoo commented 4 years ago

Hi, I'm using you library

I was trying to sign in with anothe gmail account have my same displayname and the library don't let me beacuse in line 184 in the authentication.py :

username = '_'.join(
                firebase_user.display_name.split(' ') if firebase_user.display_name \
                else str(uuid.uuid4())
            )
            username = username if len(username) <= 30 else username[:30]
            new_user = User.objects.create_user(
                username=username,
                email=email
            )

you are using username with the split of displayname, an i think a lot of persons can have the same name. Like Carlos Torres a lot of people will have this displayname but are diferent people or diferent email accounts.

I solve this changin de username with the email, let me know if work for you.

            new_user = User.objects.create_user(
                username=email,
                email=email
            )

Best Carlos

malhotrachetan commented 3 years ago

@Provoo were you able to figure out a workaround? I am facing the same issue.

garyburgmann commented 3 years ago

good idea.

feel free to create a pull req if you get to it before I do

garyburgmann commented 3 years ago

I agree, this could be done better.

I am currently developing an update, which will change this to be mapped to the firebase uid by default, with the ability to configure it via a lambda/func

This way, you could use the email, or retain the current method, or something completely different. The method will accept the firebase UserRecord as an argument

garyburgmann commented 3 years ago

@debuggermalhotra and @Provoo you can see a preview of impending change here: https://github.com/garyburgmann/drf-firebase-auth/tree/1.0.0

garyburgmann commented 3 years ago

merged into master as version 1.0.0