Seph Reed
Seph Reed

Reputation: 10928

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?

Upvotes: 49

Views: 60115

Answers (12)

Max
Max

Reputation: 1

I dont know if that is still relevant. But i faced the same issues for days. I cant really say what it was. But here is what i did.

  • I created a new key in the apple developer section.
  • Added the key in Firebase Cloud Messaging in my iOS App.
  • Added my AppStore ID
  • Turned on production mode in Firebase
  • Created a new private key in the Service Accounts Tab in Firebase
  • Added the private key in server

Cant really what it was. But i tried everything before. Nothing seemed to be working. Maybe this will help someone.

Upvotes: 0

bac ngo duc
bac ngo duc

Reputation: 1

In my case, Revoked APNs Key => the problem was solved!

Upvotes: 0

Mohammed
Mohammed

Reputation: 41

I encountered the same issue

errorInfo: {
    code: 'messaging/third-party-auth-error',
    message: 'Auth error from APNS or Web Push Service'
},
codePrefix: 'messaging'

After digging into the issue I found the missing part Firebase needs the certificate to be uploaded twice (development, production) mine was only uploaded as development. once I upload it as production too everything works enter image description here

Upvotes: 1

Alex
Alex

Reputation: 119

My mistake was using APNs certificate instead of APNs Auth key

enter image description here

Upvotes: 1

June
June

Reputation: 426

I've tried everything in this post, but it didn't work for a week. Finally, I found the mistake and am sharing it.

As a result, @Seph Reed was right. The reason for the Auth error from APNS or Web Push Service error is based on these corrections:

App Store ID
Bundle ID
Team ID

It turned out that the issue was with the Bundle ID.

In Xcode, under Signing & Capabilities, there are multiple places where you can enter the Bundle Identifier.
The topmost Bundle Identifier was left as is, with the environment variable that was automatically generated when the project was created in react-native. That part also needs to be corrected.

enter image description here

The image below shows how it should finally look enter image description here

Upvotes: 0

noone392
noone392

Reputation: 2158

Wanted to add in another reason why this might happen with ios specifically. They are upgrading to keys. So if you have certificates it might still work until may 2024 with you are debugging, but when launched it will fail to push the notifications.
in apple dev console Certificates, Identifiers & Profiles->Keys->+ then check apns
in the firebase ios upload that key and you will see a notice it will automatically disable certificates.

Upvotes: 0

J-ho
J-ho

Reputation: 273

If everything else fails, try creating new firebase project and setup push notifications for it.

For our purpose we only use firebase to send push notifications so this works. If you use it for anything else, you could separate the push notifications still to separate project and call it via HTTP-requests for example.

For some unknown reason one of our project fails on sending push notifications, it was fixed by re-creating the firebase-project.

Upvotes: 0

Henrique Troiano
Henrique Troiano

Reputation: 64

Double check if you have uploaded your apns key on firebase console. That was my case.

Upvotes: 2

MarkusDreyer
MarkusDreyer

Reputation: 340

I had the same issue. The culprit was lowercase APNs teamId. Changing it to capital solved it.

enter image description here

Upvotes: 0

Rebeloper
Rebeloper

Reputation: 792

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

Upvotes: 8

Seph Reed
Seph Reed

Reputation: 10928

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

Upvotes: 47

Related Questions