53

After running the following code 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?

1
  • Did you solve this? I have this as well. No iOS app at all - only Web Push notifications. received when sending via Oauth2 Playground. Commented Feb 12 at 22:43

16 Answers 16

51

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

Sign up to request clarification or add additional context in comments.

6 Comments

As an additional comment (b/c it took me a couple minutes to figure this out) you need to upload the APNs key you generate to Cloud Messaging => APNs Authentication Key
this post ends 3-4 days of desperately trying to display notifications for IOS with firebase in react-native - thank you sir you are an angel
In my specific case, I just renamed my bundle ID, but forgot to do that in Xcode. So the app ID, keys and APNs config in Firebase, Google Services file were all set up, but I only had to update the bundle ID in Xcode to make it work.
Expanding on @Franks comment. If you have more than one ios app then you will need to upload the APNs Auth Key for each app here console.firebase.google.com/u/1/project/hivepass-dev/settings/…
if you are confused like me about where you should create and upload the key , follow these steps how to create key in apple console : developer.apple.com/help/account/manage-keys/… where you should upload the key : go to Firebase > select your app > select CloudMessaging tab in ProjectSettings > Apple app configuration > APNs Authentication Key > upload
|
8

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

3 Comments

hi, are your requests always sent failed or just few of them? i got the similar issue.
I too am curious if this issue came back after you did this. It seems to happen on ~1% of requests I make the firebase services, I worry it's a longstanding error on their end.
Hi I tried this and it sadly didn't seem to work
1

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

enter image description here

Comments

1

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

Comments

1

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

Comments

1

My mistake was using APNs certificate instead of APNs Auth key

enter image description here

Comments

0

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.

Comments

0

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.

Comments

0

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

Comments

0

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

Comments

0

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.

Comments

0

for us on iOS, the issue was when running on debug mode, and the debug mode was using different bundleId than what registered on firebase console

Comments

0

I had the same issue. For me notifications worked during development but not in production. The issue was that my .p8 key was set to sandbox only instead of sandbox and production. https://developer.apple.com/account/resources/authkeys/list

enter image description here

Comments

0

For me The issue was that I had only uploaded the production APNs Auth Key.

For development builds, you also need to upload the Development APNs Auth Key (.p8) from Apple Developer (sandbox key) into Firebase. Once I uploaded that as well, push notifications started working. That was the missing piece.

Get your keys from :
https://developer.apple.com/account/resources/authkeys/add

And upload it to Firebase:
enter image description here

Comments

0

My problem was that I had two active APNs keys for each app im working on. The setup was correct. Apparently this is an issue, I revoked one them and used one key for both apps. Suddenly everything is working fine. So if you are dealing with this error and the setup seems correct, go to apple developer and make sure you use only one key for all apps.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.