21
votes

Recently, every time I try to add or modify the GCM API Key in an Azure Notification Hub, I get the following error:

SubCode=40000. Failed to validate credentials with GCM. The remote server returned an error: (401) Unauthorized...

I have tried using the same key that works in other Notification Hubs, as well as creating a new one via the Google Developer's console.

I've also recently come across articles stating that GCM is moving to FCM (Firebase Cloud Messaging). Could this be the cause of my issue? Is Google beginning to no longer support GCM?

2
I am having the same exact issue. The problem that I am facing is I can't seem to create the "Server Key". At least, I don't see that option under "Create credentials" in Google Cloud Console.Ming
Hi Matt, I have resolved my issue. I set the "Key restriction" for that API key to "IP addresses" and have the value set to "0.0.0.0/0", which allows all ipv4 addresses. In doing so, I was able to bypass the Unauthorized error. Hope this works for you also. :)Ming
Thanks Ming, Worked, you saved me alot of searchingJoseph Wasily
@Ming your's is the correct answer. This is accurate because in production you would have to have some security anyway. Please post your answer and have the asker accept it as correct answerAbhishek Dujari
I think @Ming s answer is correct.. Please post it as an answer.Xander

2 Answers

29
votes

There are two important informations:

So we should prefer Firebase Console instead of Google Cloud Console,

So we need to enable Google Cloud Messaging in Firebase Console for your added Android App.

Step by step:

-- Open your Firebase Console

-- Add your Android app in Firebase Console.

-- Go to Settings

-- Click CLOUD MESSAGING tab.

-- Take Legacy Server key there and use it in Azure Push Notification Service for Google(GCM) settings and Save it. That's all.

This article helps you how to create a Notification Hub Service in Azure then how to connect your Android or IOS App to Firebase Console etc.

1
votes

Could you make sure that 1) you have enabled Google Cloud Messaging for Android in your cloud push account and 2) you are creating a new Server Key?

Also, use try sending a push notification from the command line to validate that the key is working with GCM directly. If that works, then Azure portal should accept the key. If that's not the case, please leave a comment.