skip to Main Content

I’m having troubles with sending push-notifications after migrating to FCM V1

I did everything that migration docs say
https://firebase.google.com/docs/cloud-messaging/migrate-v1

  1. Created a completely new project
  2. Created a json file for jwt token creation
  3. Updated headers

Here is what my token creation code looks like (C#)

    async Task<string> GetAuthToken()
    {
        var firebaseCredentialsPath = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS");

        if (firebaseCredentialsPath != null)
        {
            GoogleCredential credential;
            using (var stream = new System.IO.FileStream(firebaseCredentialsPath,
                       System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                credential = GoogleCredential.FromStream(stream).CreateScoped("https://www.googleapis.com/auth/firebase.messaging");
            }
            
            return await ((ITokenAccess)credential).GetAccessTokenForRequestAsync();
        }

        return string.Empty;
    }

And here is how I send the request (Postman for better visual representation)
Postman configuration 1

Postman configuration 2

I am sure that the json file used for token generation belongs to a service account of the project that is mentioned in the request URL (marked with red in the screenshots).

Token is added as a bearer token in Postman (check the screenshots)

What can be the cause of the issue?
Any ideas?

2

Answers


  1. Chosen as BEST ANSWER

    As Joe Spiro mentioned, there are two types of tokens Access token and device token.

    Both tokens should be generated using the same Firebase project. Issue happened because device token was generated using another Firebase project.

    But the error message is misleading and wrong by saying that sender id is wrong. It's the recipient ID (device token) wrong, not sender ID.


  2. Sorry to hear about the confusion. Let me try to clarify this a bit:

    To be clear there are two types of token involved in this case and you are using one for the purpose of the other. You are currently generating an access token as described in the doc you linked but to send to specific devices you need to Access the device registration token as described in the send documentation and use it (again the device registration token) in your send requests.

    Hope that helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search