xtrinch / fcm-django

FCM Django: Send push notifications via django to websites, iOS & android mobile devices through FCM (Firebase Cloud Messaging)
http://fcm-django.readthedocs.io/
MIT License
775 stars 196 forks source link

Support for JWTTokenUserAuthentication #88

Closed Sebadst closed 5 years ago

Sebadst commented 5 years ago

Hello,

I am trying to register an user to fcm, however I got following exception :

Traceback (most recent call last):
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/rest_framework/viewsets.py", line 95, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/rest_framework/views.py", line 494, in dispatch
    response = self.handle_exception(exc)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/rest_framework/views.py", line 454, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/rest_framework/views.py", line 491, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/rest_framework/mixins.py", line 20, in create
    serializer.is_valid(raise_exception=True)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 236, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 438, in run_validation
    value = self.validate(value)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/fcm_django/api/rest_framework.py", line 77, in validate
    devices.filter(~Q(user=user)).update(active=False)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 784, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 802, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1250, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1270, in _add_q
    current_negated, allow_joins, split_subq)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1276, in _add_q
    allow_joins=allow_joins, split_subq=split_subq,
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1206, in build_filter
    condition = lookup_class(lhs, value)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/db/models/lookups.py", line 24, in __init__
    self.rhs = self.get_prep_lookup()
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/db/models/fields/related_lookups.py", line 112, in get_prep_lookup
    self.rhs = target_field.get_prep_value(self.rhs)
  File "/home/seba/DjangoProjects/footmash/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 966, in get_prep_value
    return int(value)
TypeError: int() argument must be a string or a number, not 'TokenUser'

In my django project I am using rest_framework_simplejwt.authentication.JWTTokenUserAuthentication in order to handle authentication, which is the reason, I guess, for which I have a TokenUser rather than the type expected. Does this mean that this project does not support JWTTokenUserAuthentication? If yes, is there any plan to support it?

xtrinch commented 5 years ago

You should be able to set the desired user model with the USER_MODEL setting which has the following default:

FCM_DJANGO_SETTINGS.setdefault("USER_MODEL", settings.AUTH_USER_MODEL)

xtrinch commented 5 years ago

Fix released with 0.3.0