NotificationHubUnauthorizedException: Unauthorized on Azure Notification Hub registration

馋奶兔 提交于 2020-01-11 09:59:51

问题


So I'm trying the Notification Hubs on Azure.

I have set things up according to this blog post. I have done the GCM setup in my Android code so I have a valid regId:

String connectionString = "Endpoint=sb://<MYNAMESPACE>.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=<MYKEY>";
hub = new NotificationHub("<MYHUB>", connectionString, this);
hub.register(regid, "myTag");

So I get:

com.microsoft.windowsazure.messaging.NotificationHubUnauthorizedException: Unauthorized

on the hub.register method call.

Any ideas?


回答1:


Unfortunately there is a bug in the management portal that corrupts a NH authorization rules. It will be solved very soon. In the meantime, you can create a new NH from a Console App and Service Bus preview dll with the following code:

NamespaceManager mgr = NamespaceManager.CreateFromConnectionString("<connection string from your namespace>");
var hub = new NotificationHubDescription("myhub");
hub.GcmCredential = new GcmCredential("<your Google API Key>");
mgr.CreateNotificationHub(hub);

Make sure to use the connection string retrieved from the portal in the following way: 1) Click Service Bus on the left pane 2) On the right-pane, select your namespace, then click Connection Information 3) Copy the Connection String for RootAccess, as shown below:

Sorry for the inconvenience.




回答2:


This issue is resolved now. Use the management portal to manage your notification hub. If the Authorization rules are not present on the Notification Hub then add the rules in the portal and copy the corresponding connection string to use with Notification Hub android API.



来源:https://stackoverflow.com/questions/17136263/notificationhubunauthorizedexception-unauthorized-on-azure-notification-hub-reg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!