dgilland/flask-pushjack

Device token for apns resulting on a error

rafagonc opened this issue · 3 comments

I'm passing the device token as a string like 'aa312fdc...' and it's resulting in a validation error.

What is the correct format of the device token?

Device token should be a string of length 64. The client-side validation function used is here: https://github.com/dgilland/pushjack/blob/1deead88cad51c42635c69d988b6a96be36e3d50/pushjack/apns.py#L741

Are you receiving a APNSInvalidTokenError error from pushjack? Or is the error from the APNS response?

I was receiving the APNSInvalidTokenError from the 'assert unhexlify(token)', after commenting it, it was ok and the notifications have arrived.

So if I understand you correctly, you are saying that you commented out the line assert unhexlify(token) from the valid_token() function which prevented the APNSInvalidTokenError from being raised and allowed notifications to be sent?

If that is the case, that is puzzling because during message packing, unhexlify(token) is called again: https://github.com/dgilland/pushjack/blob/1deead88cad51c42635c69d988b6a96be36e3d50/pushjack/apns.py#L562. So it's strange that one fails while the other does not.

Two main reasons that cause unhexlify to fail are (1) if the string contains non-hex characters (i.e. not 0-9a-f) or (2) if the length of the string is an odd number.

Can you verify a few things:

  1. What type is the token object?
  2. What is the length of the token object?
  3. What are the unique characters of the token? (e.g. ''.join(set(token)))
  4. What version of Python are you running?