firebasefirebase-authenticationfirebase-cloud-messaging

Firebase Error: Auth error from APNS or Web Push Service


After running the following line in node-js:

import * as admin from "firebase-admin";
import * as serviceAccount from "../../firebase_service_account_key.json";

const app = admin.initializeApp({
  credential: admin.credential.cert(serviceAccount as any),
  databaseURL: "https://my-app-path.firebaseio.com"
});

admin.messaging().send({
    token: "known-good-token",
    notification: {
        title: "Test Push Note",
        body: "Here is some text"
    }
});

I'm getting the error:

Error: Auth error from APNS or Web Push Service 
Raw server response: 
"{
  "error":{
    "code":401,
    "message":"Auth error from APNS or Web Push Service",
    "status":"UNAUTHENTICATED",
    "details"[
      {
        "@type":"type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode":"THIRD_PARTY_AUTH_ERROR"
      },
      {
        "@type":"type.googleapis.com/google.firebase.fcm.v1.ApnsError",
        "statusCode":403,
        "reason":"InvalidProviderToken"
      }
    ]
  }
}"

I've added an "APNs Authentication Key" to my ios project under the Settings > Cloud Messaging section of Firebase. I've also properly downloaded and imported my service account json file.

In terms of research, I've tried looking up the errors.

auth/unauthorized-domain

Thrown if the app domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console.

Does anyone have anymore details on this error which might help me get to the bottom of it?


Solution

  • This error arises if your app setup for iOS has an error in any one of the following:

    Found in Settings > General > Your Apps > iOS Apps:

    enter image description here

    When adding an APNs key (Uploading to Cloud Messaging > APNs Authentication Key):

    enter image description here