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
128 stars 62 forks source link

Not Working for Firebase Mobile Authentication #4

Open rishav00a opened 5 years ago

rishav00a commented 5 years ago

I am using Firebase Mobile Auth, and getting error it is searching for email and obviously thats not available in phone authentication, please look at the issue.

Internal Server Error: /api/events/upcoming_events Traceback (most recent call last): File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\drf_firebase_auth\authentication.py", line 158, in get_or_create_local_user user = User.objects.get(email=email) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\django\db\models\query.py", line 399, in get self.model._meta.object_name django.contrib.auth.models.User.DoesNotExist: User matching query does not exist.

During handling of the above exception, another exception occurred: Traceback (most recent call last): File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\request.py", line 77, in wrap_attributeerrors yield File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\request.py", line 223, in user self._authenticate() File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\request.py", line 376, in _authenticate user_auth_tuple = authenticator.authenticate(self) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\drf_firebase_auth\authentication.py", line 51, in authenticate local_user = self.get_or_create_local_user(firebase_user) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\drf_firebase_auth\authentication.py", line 182, in get_or_create_local_user display_name = firebase_user.display_name.split() AttributeError: 'NoneType' object has no attribute 'split'

Traceback (most recent call last): File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response response = self.process_exception_by_middleware(e, request) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view return view_func(*args, **kwargs) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\django\views\generic\base.py", line 68, in view return self.dispatch(request, *args, **kwargs) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\views.py", line 495, in dispatch response = self.handle_exception(exc) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\views.py", line 455, in handle_exception self.raise_uncaught_exception(exc) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\views.py", line 483, in dispatch self.initial(request, *args, **kwargs) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\views.py", line 400, in initial self.perform_authentication(request) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\views.py", line 326, in perform_authentication request.user File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\request.py", line 223, in user self._authenticate() File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\contextlib.py", line 99, in __exit__ self.gen.throw(type, value, traceback) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\request.py", line 81, in wrap_attributeerrors six.reraise(type(exc), exc, info[2]) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\django\utils\six.py", line 683, in reraise raise value.with_traceback(tb) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\request.py", line 77, in wrap_attributeerrors yield File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\request.py", line 223, in user self._authenticate() File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\rest_framework\request.py", line 376, in _authenticate user_auth_tuple = authenticator.authenticate(self) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\drf_firebase_auth\authentication.py", line 51, in authenticate local_user = self.get_or_create_local_user(firebase_user) File "F:\ProgramData\Anaconda3\envs\MyEnv\lib\site-packages\drf_firebase_auth\authentication.py", line 182, in get_or_create_local_user display_name = firebase_user.display_name.split() rest_framework.request.WrappedAttributeError: 'NoneType' object has no attribute 'split' [28/Mar/2019 19:21:19] "GET /api/events/upcoming_events HTTP/1.1" 500 21332

garyburgmann commented 5 years ago

That is a good point. Django works with a required username and email, which would be problematic with a mobile only approach in any case. The only way to work around this would be to take a similar work around approach like an AnonymousUser, in which case the request would be granted access but you would not be able to marry up the requesting user to Api data. If you are just offering up data, this may not be problematic for you. This is something I may look at in the future, but if you have an idea feel free to make a pull request.

Arka-cell commented 3 years ago

@garyburgmann Are you still into adding a mobile authentication feature? I'll be here to contribute.

garyburgmann commented 3 years ago

@Arka-cell I have not investigated at it at this stage