Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • For the InvalidProviderToken error, this answer seems to indicate I'm using an old token. This is totally possible, but the logs on my app and database appear to match, so it seems off.

  • As for the THIRD_PARTY_AUTH_ERROR, google gave me no hits. The closest thing I found was this, and the following text might be the culprit (EDIT: it's not the issue):

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?

like image 748
Seph Reed Avatar asked May 03 '19 22:05

Seph Reed


People also ask

How do I upload a APN to Firebase?

Upload your APNs authentication key Inside your project in the Firebase console, select the gear icon, select Project Settings, and then select the Cloud Messaging tab. In APNs authentication key under iOS app configuration, click the Upload button.

What is FCM & APNs?

Pusher relies on Firebase Cloud Messaging (FCM) for Android, and Apple Push Notification service (APNs) for iOS to deliver push notifications on your behalf.

What is APNs in firebase?

To receive a push notification, your device needs to be registered with the Apple Push Notification service (APNs) by receiving a unique device token. Once the device is registered, you can send push notifications to the device by sending a request to APNs using the device token.

How do I find my firebase error code?

Usefirebase. auth. Error. code to get the specific error code.


2 Answers

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:

  • App Store ID
  • Bundle ID
  • Team ID

enter image description here

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

  • Team ID (should auto set based off ios app info above)
  • Key Id (often is in the name of the key, best to grab when creating it)

enter image description here

like image 172
Seph Reed Avatar answered Sep 19 '22 15:09

Seph Reed


Everything worked for me the other day, so all setup was fine. But today I got this error.

Here's what solved it for me:

  1. Revoked APNs Key
  2. Created new one and downloaded it
  3. Deleted old one and Uploaded it to Firebase Dashboard / Settings / Cloud Messaging
  4. Gone to Settings / Service Accounts and generated new private key
  5. Added it to my Cloud Functions project (renamed it to service-account.json in my case)
  6. Saved the files and deployed the functions: firebase deploy --only functions
like image 45
Rebeloper Avatar answered Sep 19 '22 15:09

Rebeloper