azure - 在 Azure 通知中心注册设备时不断获得未经授权的情况

标签 azure azure-notificationhub

我已经按照“t”的每个示例进行操作,并且无法让 Azure 通知中心返回除以下 401 消息之外的任何内容:“MalformedToken:授权 header 中包含的凭据不是 WRAP 格式。”

我尝试了命名空间访问键和通知中心键,但没有成功。我按照这里的例子:https://msdn.microsoft.com/en-us/library/azure/dn495630.aspx并且一直无法让它发挥作用。我更改了所有帐户特定设置,例如命名空间、通知中心名称和授权 key 。

var registrationXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
            "<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
                "<content type=\"application/xml\">" +
                    "<GcmTemplateRegistrationDescription xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">" +
                        "<GcmRegistrationId>" + {GCMRegID} + "</GcmRegistrationId> " +
                        "<BodyTemplate><![CDATA[ {\"data\": { \"message\": \"$(msg)\" } }]]></BodyTemplate>" +
                    "</GcmTemplateRegistrationDescription>" +
                "</content>" +
            "</entry>";

        $.ajax(
            {
                type: "POST",
                url: "https://{myNamespace}.servicebus.windows.net/{myHubName}/registrations/?api-version=2015-01",
                headers: { 'Authorization': '{myAccessKey}', 'Content-Type': 'application/atom+xml;type=entry;charset=utf-8', 'x-ms-version': '2015-01' },
                data: registrationXML,
                dataType: "xml",
                contentType: "text/xml",
                success: function (data) {
                    debugger;
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    debugger;
                }
            });

最佳答案

{myAccessKey} 的值应类似于:

SharedAccessSignature sig=<signature-string>&se=<expiry>&skn=<keyName>&sr=<URL-encoded-resourceURI>

构建签名的文档位于 https://msdn.microsoft.com/en-us/library/azure/dn170477.aspx

关于azure - 在 Azure 通知中心注册设备时不断获得未经授权的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31174499/

相关文章:

azure - 使用 NotificationHub 集成在 Visual Studio 上创建的 Azure 函数时出错

android - Azure 通知中心不再接受 GCM API key

c# - 我在尝试向多部 iPhone 发送消息时遇到一些问题

azure - 如何从发布管道/ARM 模板设置 Application Insights

Azure数据工厂: Migration of pipelines from one data factory to another

Azure服务总线: No session available to complete the message with the lock token

c# - Azure Function 异常无法加载 ActiveDirectory 文件或程序集

Azure DevOps yaml管道部署: "Provider phase is not supported"

c# - 以编程方式使用 Sandbox 的 azure CreateNotificationHub

azure - 更新通知中心时出错