diff --git a/changelog.d/344.feature b/changelog.d/344.feature new file mode 100644 index 00000000..bbc908d1 --- /dev/null +++ b/changelog.d/344.feature @@ -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. \ No newline at end of file diff --git a/sygnal.yaml.sample b/sygnal.yaml.sample index 0a2c9b3c..b62d564f 100644 --- a/sygnal.yaml.sample +++ b/sygnal.yaml.sample @@ -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. # diff --git a/sygnal/apnspushkin.py b/sygnal/apnspushkin.py index e47374d7..0dd588b1 100644 --- a/sygnal/apnspushkin.py +++ b/sygnal/apnspushkin.py @@ -242,7 +242,12 @@ async def _dispatch_request( log.info(f"Sending as APNs-ID {notif_id}") 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,