parse-community / parse-server-push-adapter

A push notification adapter for Parse Server
https://parseplatform.org
MIT License
87 stars 99 forks source link

GCM error 401 when sending a push via adapter #35

Closed DeDuckProject closed 7 years ago

DeDuckProject commented 7 years ago

Edit: I solved it as follows: Apparently GCM changed the way you create API keys. They no longer let you choose between server, browser, etc.. But I think their default doesn't whitelist all IPs so once I explicitly added my local public IP and my server's public IP I stopped getting this error.

Hi, I'm trying to send a push using the default GCM adapter. I get an 401 error. My server config is configured ok, I know this because the correct apiKey is used when needed in the adapter (when I'm debugging).

What I find strange, is that in no place, the senderId is used

on init this code is executed:

function GCM(args) {
  if ((typeof args === 'undefined' ? 'undefined' : _typeof(args)) !== 'object' || !args.apiKey) {
    throw new _parse2.default.Error(_parse2.default.Error.PUSH_MISCONFIGURED, 'GCM Configuration is invalid');
  }
  this.sender = new _nodeGcm2.default.Sender(args.apiKey);
}

args holdes the proper apiKey and senderId but the senderId is disregarded and the this.sender only takes the apiKey. I've not found any code use for senderId.

I'm running parse-server version 2.2.17

note that I've noticed that google API changed their API key usage a bit, and not instead of choosing between ios,server, browser or android - the default is simply creating a non-restricted API key, which is what I did. Triple checked the API key, and generated new ones and tried them as well... Waited 5 minutes. and then that 401 error.

Anyone have a clue or direction?

Hitabis commented 7 years ago

@DeDuckProject where did you add your ip? In the "key restriction" of the api key? How did you enter your development server?

DeDuckProject commented 7 years ago

In key restriction i changed to IP and added the server IPs

Hitabis commented 7 years ago

@DeDuckProject thanks. But didn't work for me. I ended up using an old key. This one was created before google changed to FCM. I don't know if this is the reason.

DeDuckProject commented 7 years ago

@Hitabis yes you are right. It first worked for me when I used the old key. and then I did what I wrote :)

robertdo commented 7 years ago

I had this same problem and this is due to poor documentation by Google and Firebase teams. You can't use the key created in the Google Developers console. You must import your project into a Firebase project and use the GCM key they provide there.

Pfennigbaum commented 7 years ago

We had to use the Web Api Key found in Project Settings and not the Server Key found under Cloud Messagin.