Skip to content

GCM error 401 when sending a push via adapter #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DeDuckProject opened this issue Sep 13, 2016 · 6 comments
Closed

GCM error 401 when sending a push via adapter #35

DeDuckProject opened this issue Sep 13, 2016 · 6 comments

Comments

@DeDuckProject
Copy link

DeDuckProject commented Sep 13, 2016

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
Copy link

Hitabis commented Sep 16, 2016

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

@DeDuckProject
Copy link
Author

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

@Hitabis
Copy link

Hitabis commented Sep 20, 2016

@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
Copy link
Author

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

@robertdo
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants