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
Module 'firebase_admin.auth' has no attribute 'AuthError' #13
During processing a request with expired token or invalid token AuthError exception failed to be thrown
To reproduce - just send an invalid token
Invalid token trace
Traceback (most recent call last):
File "/opt/python/lib/python3.8/site-packages/drf_firebase_auth/authentication.py", line 118, in decode_token
return firebase_auth.verify_id_token(
File "/opt/python/lib/python3.8/site-packages/firebase_admin/auth.py", line 179, in verify_id_token
verified_claims = token_verifier.verify_id_token(id_token)
File "/opt/python/lib/python3.8/site-packages/firebase_admin/_token_gen.py", line 234, in verify_id_token
return self.id_token_verifier.verify(id_token, self.request)
File "/opt/python/lib/python3.8/site-packages/firebase_admin/_token_gen.py", line 272, in verify
header, payload = self._decode_unverified(token)
File "/opt/python/lib/python3.8/site-packages/firebase_admin/_token_gen.py", line 348, in _decode_unverified
raise self._invalid_token_error(str(error), cause=error)
firebase_admin._auth_utils.InvalidIdTokenError: Wrong number of segments in token: b'undefined'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 74, in wrap_attributeerrors
yield
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 220, in user
self._authenticate()
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 373, in _authenticate
user_auth_tuple = authenticator.authenticate(self)
File "/opt/python/lib/python3.8/site-packages/drf_firebase_auth/authentication.py", line 57, in authenticate
decoded_token = self.decode_token(firebase_token)
File "/opt/python/lib/python3.8/site-packages/drf_firebase_auth/authentication.py", line 127, in decode_token
except firebase_auth.AuthError as exc:
AttributeError: module 'firebase_admin.auth' has no attribute 'AuthError'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/python/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/opt/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/opt/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/python/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/opt/python/lib/python3.8/site-packages/rest_framework/viewsets.py", line 114, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 505, in dispatch
response = self.handle_exception(exc)
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 465, in handle_exception
self.raise_uncaught_exception(exc)
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
raise exc
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 493, in dispatch
self.initial(request, *args, **kwargs)
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 410, in initial
self.perform_authentication(request)
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 324, in perform_authentication
request.user
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 220, in user
self._authenticate()
File "/usr/local/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 78, in wrap_attributeerrors
raise exc.with_traceback(info[2])
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 74, in wrap_attributeerrors
yield
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 220, in user
self._authenticate()
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 373, in _authenticate
user_auth_tuple = authenticator.authenticate(self)
File "/opt/python/lib/python3.8/site-packages/drf_firebase_auth/authentication.py", line 57, in authenticate
decoded_token = self.decode_token(firebase_token)
File "/opt/python/lib/python3.8/site-packages/drf_firebase_auth/authentication.py", line 127, in decode_token
except firebase_auth.AuthError as exc:
rest_framework.request.WrappedAttributeError: module 'firebase_admin.auth' has no attribute 'AuthError'
Expired token
Traceback (most recent call last):
File "/opt/python/lib/python3.8/site-packages/drf_firebase_auth/authentication.py", line 118, in decode_token
return firebase_auth.verify_id_token(
File "/opt/python/lib/python3.8/site-packages/firebase_admin/auth.py", line 179, in verify_id_token
verified_claims = token_verifier.verify_id_token(id_token)
File "/opt/python/lib/python3.8/site-packages/firebase_admin/_token_gen.py", line 234, in verify_id_token
return self.id_token_verifier.verify(id_token, self.request)
File "/opt/python/lib/python3.8/site-packages/firebase_admin/_token_gen.py", line 339, in verify
raise self._expired_token_error(str(error), cause=error)
firebase_admin._token_gen.ExpiredIdTokenError: Token expired, 1580047340 < 1580053167
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 74, in wrap_attributeerrors
yield
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 220, in user
self._authenticate()
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 373, in _authenticate
user_auth_tuple = authenticator.authenticate(self)
File "/opt/python/lib/python3.8/site-packages/drf_firebase_auth/authentication.py", line 57, in authenticate
decoded_token = self.decode_token(firebase_token)
File "/opt/python/lib/python3.8/site-packages/drf_firebase_auth/authentication.py", line 127, in decode_token
except firebase_auth.AuthError as exc:
AttributeError: module 'firebase_admin.auth' has no attribute 'AuthError'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/python/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/opt/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/opt/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/python/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/opt/python/lib/python3.8/site-packages/rest_framework/viewsets.py", line 114, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 505, in dispatch
response = self.handle_exception(exc)
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 465, in handle_exception
self.raise_uncaught_exception(exc)
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
raise exc
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 493, in dispatch
self.initial(request, *args, **kwargs)
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 410, in initial
self.perform_authentication(request)
File "/opt/python/lib/python3.8/site-packages/rest_framework/views.py", line 324, in perform_authentication
request.user
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 220, in user
self._authenticate()
File "/usr/local/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 78, in wrap_attributeerrors
raise exc.with_traceback(info[2])
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 74, in wrap_attributeerrors
yield
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 220, in user
self._authenticate()
File "/opt/python/lib/python3.8/site-packages/rest_framework/request.py", line 373, in _authenticate
user_auth_tuple = authenticator.authenticate(self)
File "/opt/python/lib/python3.8/site-packages/drf_firebase_auth/authentication.py", line 57, in authenticate
decoded_token = self.decode_token(firebase_token)
File "/opt/python/lib/python3.8/site-packages/drf_firebase_auth/authentication.py", line 127, in decode_token
except firebase_auth.AuthError as exc:
rest_framework.request.WrappedAttributeError: module 'firebase_admin.auth' has no attribute 'AuthError'
Versions
During processing a request with expired token or invalid token AuthError exception failed to be thrown
To reproduce - just send an invalid token
Invalid token trace
Expired token