Skip to content

Commit

Permalink
Allow to configure if pushkey should be converted to hex before sendi…
Browse files Browse the repository at this point in the history
…ng to APNs (#344)

Some APNs libraries give the pushkey in hex directly, but sygnal assumes
that the pushkey is given in base64 (and attempts to convert it to hex).

This adds a configuration option to avoid this processing / assumption.
  • Loading branch information
danbim authored Nov 30, 2023
1 parent 23d62ca commit e2eaa5c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/344.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a new `convert_device_token_to_hex` configuration option for APNs apps, to allow disabling the conversion of device tokens from base64 to hex.
5 changes: 5 additions & 0 deletions sygnal.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ apps:
# #
# # The default is 'production'. Uncomment to use the sandbox instance.
# #platform: sandbox
# #
# # Specifies whether to convert the device push token from base 64 to hex.
# # Defaults to True, set this to False if your client library provides a
# # push token in hex format.
# #convert_device_token_to_hex: false

# This is an example GCM/FCM push configuration.
#
Expand Down
7 changes: 6 additions & 1 deletion sygnal/apnspushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ async def _dispatch_request(
"""
span.set_tag("apns_id", notif_id)

device_token = base64.b64decode(device.pushkey).hex()
# Some client libraries will provide the push token in hex format already. Avoid
# attempting to convert from base 64 to hex.
if self.get_config("convert_device_token_to_hex", bool, True):
device_token = base64.b64decode(device.pushkey).hex()
else:
device_token = device.pushkey

request = NotificationRequest(
device_token=device_token,
Expand Down

0 comments on commit e2eaa5c

Please sign in to comment.