Skip to content
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

messaging/authentication-error #302

Closed
coyksdev opened this issue Jul 10, 2018 · 4 comments
Closed

messaging/authentication-error #302

coyksdev opened this issue Jul 10, 2018 · 4 comments

Comments

@coyksdev
Copy link

I followed the firebase docs on how to create an firebase admin for push notifications. this is how i set it up.

const admin = require('firebase-admin');
const serviceAccount = require('../helpers/privateKey.json');
const { fireBasePushNotification } = require('../config');

admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: fireBasePushNotification.database
});

var registrationTokens = [
'imagine this is a token'
];

var topic = 'myTopic'

admin.messaging().subscribeToTopic(registrationTokens, topic)
.then(function(response) {
// See the MessagingTopicManagementResponse reference documentation
// for the contents of response.
console.log('Successfully subscribed to topic:', response);
})
.catch(function(error) {
console.log('Error subscribing to topic:', error);
});

but when i tried to subscribe a topic it respond an error "messaging/authentication-error"
The SDK could not authenticate to the FCM servers. Make sure you authenticate the Admin SDK with a credential which has the proper permissions to send FCM messages. See Add Firebase to your app for documentation on how to authenticate the Admin SDKs.

I generated serviceAccountKey several times it doesnt work.

@google-oss-bot
Copy link

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@google-oss-bot
Copy link

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

@Rua-Yuki
Copy link

Please make sure that the tokens you generate on the frontend are created by a Firebase app instance with a messagingSenderId matching your project's Sender ID.

For instance, if the Firebase console indicates that your project has a Sender ID of 012345678912, you should initialize your app on the frontend with this same ID specified, like so:

firebase.initializeApp({ messagingSenderId: '012345678912' });

By initializing the app with a proper Sender ID corresponding to your project, the generated tokens should now work with FCM registration functions used on the backend.

You can find your Sender ID by following these steps:

  1. Login to the Firebase console.
  2. Select the desired project.
  3. Tap the gear icon, located near the top-left of the page: a popup-menu will appear.
  4. Select "Project settings" from the displayed popup-menu.
  5. Select the "Cloud Messaging" tab.
  6. Your Sender ID should be just a few rows down, below your server keys.

@hiranya911
Copy link
Contributor

Dupe of #303

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