Azure Notifications Hub - iOS MDM push notifications

Curling Log 26 Reputation points
2021-06-30T14:46:21.923+00:00

Hi,

Is it possible to send an MDM push notification (as opposed to a standard Apple push notification) using Azure Notifications Hub?

We have been using the PushSharp C# library to successfully send the MDM push notifications which are in the format {”mdm”:”PushMagicValue”} using our Apple MDM push certificate

Note this is the full message, there is no wrapping in an "aps" object required for MDM push notifications

However we would like to switch to use Azure Notifications Hub if possible, it appears AWS SNS may allow the MDM push notifications to be sent, but ideally we'd like to keep this on Azure given all our other services are

Using the Notifications Hub client, it gives the following error:

Microsoft.Azure.NotificationHubs.Messaging.BadRequestException: ' The supplied notification payload is invalid.TrackingId:[Redacted],TimeStamp:6/30/2021 2:59:21 PM'

https://developer.apple.com/business/documentation/MDM-Protocol-Reference.pdf page 18 here shows the payload details

Thanks for your time

Azure Notification Hubs
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
300 questions
0 comments No comments
{count} votes

Accepted answer
  1. Grmacjon-MSFT 17,456 Reputation points
    2021-07-02T19:40:56.517+00:00

    Hi @Curling Log ,

    I reached out internally to the engineering team and they said this isn’t an officially supported scenario on Azure Notifications Hub. However, there is a workaround. You will need to provide the apns-push-type header with the value mdm. The payload also needs to contain an empty aps object to pass our validation (i.e. {“aps”: {}, “mdm”: “PushMagicValue”}.

    Hope that helps.

    Thanks!
    Grace

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Curling Log 26 Reputation points
    2021-07-06T15:11:13.823+00:00

    Hi Grace,

    Thank you for your reply, I can confirm that this workaround does work.

    • Is this workaround something we can rely on long term or is it possible it will get removed?
    • Are there any plans to add native Apple MDM push support to the Azure Notifications Hub service?

    Thanks

    For anyone else following, here is some sample code to send an MDM push notification via Azure Notification Hubs to a device you already have a push token and push magic string for and where you have already uploaded the MDM push certificate to ANH portal

         public async Task SendMdmNotification()
            {
                var azureNotificationsConnectionString = "[YOUR-SHARED-ACCESS-KEY]";
    
                var azureHubName = "[YOUR-HUB-NAME]"; 
    
                var notificationHubClient = NotificationHubClient.CreateClientFromConnectionString(azureNotificationsConnectionString, azureHubName);
    
                var registration = await notificationHubClient.CreateAppleNativeRegistrationAsync("[DEVICE-PUSH-TOKEN]", new[] { "test-device" });
    
                var headers = new Dictionary<string, string>
                {
                    { "apns-push-type", "mdm"},
                    { "apns-topic", "com.apple.mgmt.External.[YOUR-PUSH-CERTIFICATE-TOPIC]"},
                    { "apns-id", Guid.NewGuid().ToString()},
                    { "apns-expiration", "0"},
                    { "apns-priority", "10"}
                };
    
                var message = $@"{{ ""aps"": {{}}, ""mdm"": ""[YOUR-DEVICE-PUSH-MAGIC-STRING]""}}";
    
                var notification = new AppleNotification(message, headers);
    
                var result = await notificationHubClient.SendNotificationAsync(notification, "test-device", CancellationToken.None);
            }
    
    1 person found this answer helpful.